我正在制作一个简单的脚本,从不同的工作簿中取出一堆工作表并将它们放在一个工作簿上。我必须重命名所有工作表,以便它们与我拥有的其他脚本一起使用。除了我从 eod 循环中获得的工作表之外,所有工作表都被重命名了。前两张纸被重命名得很好,但之后循环中的一张都没有。来自 eod 表的所有工作簿都是 xlsx 格式,其余的是 xls 格式。宏完成后,我放入的每张 xls 表格都会关闭,但所有 xlsx 格式文件都不会。我不知道这是否是问题的一部分。什么会导致这只重命名某些工作表?
Sub getSheets()
num = 1
-----> ' loop for eod
Do Until copyover("Weekly", "EOD Week " & num) = False
num = num + 1
Loop
temp = copyover("Voice_of_the_Customer", "VOC")
temp = copyover("Daily_Cp%_v2", "COMP")
temp = copyover("MPJ-Scorecard-QC-Summary", "QC")
temp = copyover("MPJ-Scorecard-SCOI-Summary", "SCOI")
temp = copyover("TechUpstreamTransmit", "UPSQ")
temp = copyover("Daily_CCG_OTG", "MTF")
temp = copyover("summary", "S7 QC")
temp = copyover("MPJ-Scorecard-TCF-Summary", "TCF")
End Sub
Function copyover(SheetAd As String, SheetName As String) As Boolean
Dim origWork As Workbook
Dim fileName As String
Dim copytoFile As Variant
Dim copytoFile2 As Workbook
Set origWork = ActiveWorkbook
tem = MsgBox("Do you want to add " & SheetName, vbYesNoCancel)
If (tem = vbYes) Then
copyover = True
On Error GoTo ErrHandler
copytoFile = Application.GetOpenFilename _
(Title:=SheetAd, _
FileFilter:="Excel Files *.x* (*.x*),")
Workbooks.Open copytoFile
Set copytoFile2 = ActiveWorkbook
copytoFile2.Sheets(SheetAd).Move After:=origWork.Sheets("TechScore")
'ActiveSheet.Name = SheetName
origWork.Activate
origWork.Sheets(SheetAd).Name = SheetName
'ThisWorkbook.VBProject.VBComponents(SheetAd).Name = "Mudface"
Workbooks(copytoFile).Close False
Else
If (tem = vbNo) Then
copyover = False
End If
End If
ErrHandler:
End Function