我有一个可以备份的宏。我希望宏可用于我的所有工作簿,所以我将它放在我的 personal.xlsb 文件中。但是备份保存在 .xlsb 路径上,而不是我正在实际工作的工作簿的路径上......也许是 Application.ThisWorkbook.path 代码
Sub Backup()
'makes backup
Dim MyDate
MyDate = Date
Dim myTime
myTime = Time
Dim TestStr As String
TestStr = Format(myTime, "hh.mm.ss")
Dim Test1Str As String
Test1Str = Format(MyDate, "DD-MM-YYYY")
Dim strFolderName As String
Dim strFolderExists As String
Dim path As String
'the problem must be in the code below
path = Application.ThisWorkbook.path
strFolderName = path & "\Backup\"
strFolderExists = Dir(strFolderName, vbDirectory)
Debug.Print path
Application.DisplayAlerts = False
If strFolderExists = "" Then
MkDir strFolderName
path = strFolderName & Test1Str & "_" & TestStr & "_" & ActiveWorkbook.Name
Else
path = strFolderName & Test1Str & "_" & TestStr & "_" & ActiveWorkbook.Name
End If
ActiveWorkbook.SaveCopyAs Filename:=path
Application.DisplayAlerts = True
End Sub