当“1 个工作簿”的“在同一个活动会话中”我必须通过一个按钮和我编写的代码创建不同的工作簿来将一些(几个)工作表导出到不同的目录时,我遇到了一个问题。问题是 excel 自动给新地图命名,例如,当第一个工作簿创建时,它会自动调用它 map 1 ,第二个工作簿将调用 map 2 ,第三个等等。有没有办法让 VBA例如,总是参考新创建的地图而不参考地图 1?在代码过程中,我必须参考新地图(在我的工作簿的每个工作表中),但我现在必须将它们全部命名为地图 1(在我的代码中)。当我关闭主工作簿并再次重新打开,但这不是它应该工作的方式。我可以输入一些 DIM 设置并参考新创建的工作簿吗?我相信这个问题之前没有被问到这个具体的问题。谢谢...
我试图简化代码以使其易于理解。实际上,我应该从 Thisworkbook 翻到 WbNew。我希望我能把我的问题说得足够清楚。我也尝试提出一些建议的设置。
Sub Testing Macro()
Dim wbNew as Workbook
' Testing Macro
'How can I command to switch over workbooks without counting the excelnumbers of workbooks?
'switching and savings are not working at the moment.
'we always start from Thisworkbook.
' This workbook is the original workbook
'Wbnew should be the new created Workbook (each new created and active Wb of course) , the new Wb will be closed after process
ThisWorkbook.Sheets("SPECIFIC").Activate
Range("A1:AS291").Select
Selection.copy
Set wbNew = Workbooks.Add
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ThisWorkbook.Sheets("SPECIFIC").Activate
ActiveSheet.Shapes.Range(Array("Picture 1")).Select
Selection.copy
Wbnew.Activate
ActiveSheet.Paste
Application.CutCopyMode = False
WbNew.Activate
--> some formulas here
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
-->some page setting here
End With
Application.PrintCommunication = True
WbNew.SaveAs Filename:= _
ThisWorkbook.Path & "\Path\" & ".xlsx"
FileFormat = xlOpenXMLWorkbook
ActiveWindow.Close
End Sub