我在網上發現了一些VBA代碼,並對我需要的內容進行了修改。我遇到了能夠改變路徑的一個問題。我的印象是:硬編碼VBA SaveAs路徑?
CurrentFile = ThisWorkbook.FullName
會再打完整的文件名,包括路徑到當前保存,但是當我運行是不言而喻的代碼到我的/文件(未在該文件被保存)。有沒有辦法可以用硬編碼路徑修改下面的內容?
Sub SaveWorkbookAsNewFile()
Dim ActSheet As Worksheet
Dim ActBook As Workbook
Dim CurrentFile As String
Dim NewFileType As String
Dim NewFile As String
Dim NewFileName As String
NewFileName = "Checklist " & Format(Now, "MMMM-dd-yyyy")
Application.ScreenUpdating = False ' Prevents screen refreshing.
CurrentFile = ThisWorkbook.FullName
NewFileType = "Excel Files 1997-2003 (*.xls), *.xls," & _
"Excel Files 2007 (*.xlsx), *.xlsx," & _
"All files (*.*), *.*"
NewFile = Application.GetSaveAsFilename(_
InitialFileName:=NewFileName, _
fileFilter:=NewFileType)
If NewFile <> "" And NewFile <> "False" Then
ActiveWorkbook.SaveAs filename:=NewFile, _
FileFormat:=xlNormal, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Set ActBook = ActiveWorkbook
Workbooks.Open CurrentFile
ActBook.Close
End If
Application.ScreenUpdating = True
末次在這裏代碼
不喜歡它。你有沒有看到爲什麼這不會抓住當前文件路徑的任何原因?如果我能夠解決這個問題,那將會很棒 – user2679225
@ user2679225看看編輯。 – BigElittles