以下是数据操作宏的最后一部分的片段:
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
最后,它将文件保存为无宏工作簿,然后打开新文件。
为什么这样做会关闭旧文件?
(换句话说,在运行行Windows("Aspects List.xlsx").Activate
后停止宏执行 - 后续行永远不会被执行。)
答案 0 :(得分:1)
只需删除此行
即可Workbooks.Open Filename:=newFileFullName
执行ActiveWorkbook.SaveAs
后,您的有效工作簿已经引用Aspects List.xlsx
:
SaveAs
之前:
SaveAs
后:
顺便说一下,在我看来
newFilePath = Left(ThisWorkbook.FullName, fullfilenamelength - filenamelength)
可以简化为
newFilePath = ThisWorkbook.Path & "\"