将文件保存为无macros的macros将closures原始文件
以下是数据操作macros的最后一部分的代码片段:
Cells.EntireColumn.AutoFit Application.ScreenUpdating = True Dim fullfilenamelength As Integer, filenamelength As Integer fullfilenamelength = Len(ThisWorkbook.FullName) filenamelength = Len(udfWBFilename("ThisOne")) Dim newFilePath As String, newFileFullName As String newFilePath = Left(ThisWorkbook.FullName, fullfilenamelength - filenamelength) newFileFullName = newFilePath & "Aspects List.xlsx" ActiveWorkbook.SaveAs Filename:=newFileFullName, FileFormat _ :=xlOpenXMLWorkbook, CreateBackup:=False Workbooks.Open Filename:=newFileFullName Windows("Aspects List.xlsx").Activate Beep Application.DisplayAlerts = True Application.StatusBar = False End Sub
在这里最后,它将文件保存为一个无macros的工作簿,然后打开新文件。
为什么在这样做时closures旧文件? (换句话说,macros执行在运行Windows("Aspects List.xlsx").Activate
行后停止Windows("Aspects List.xlsx").Activate
– 后续行从不执行。)
只要删除这一行
Workbooks.Open Filename:=newFileFullName
执行ActiveWorkbook.SaveAs
,您的活动工作簿已引用Aspects List.xlsx
:
在SaveAs
之前:
在SaveAs
之后:
顺便说一句,在我看来,这
newFilePath = Left(ThisWorkbook.FullName, fullfilenamelength - filenamelength)
可以简化为
newFilePath = ThisWorkbook.Path & "\"
另外它可能很有趣: 如何避免使用Select / Active语句