當我運行此代碼時,我收到以下錯誤訊息,如果檔案夾不存在,我可以創建檔案夾以在其中保存檔案:“運行時錯誤 75 路徑/檔案訪問錯誤”
有什么想法嗎?
Sub auto_organize_save1()
Dim fdObj As Object
Dim folder As String
Set fdObj = CreateObject("Scripting.FileSystemObject")
folderYear = "C:\temp\testing\" & Format(Now, "YYYY") & "\"
folderMonth = "C:\temp\testing\" & Format(Now, "YYYY") & "\" & Format(Now, "MM-MMM") & "\"
If Not fdObj.FolderExists(folder) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folder) Then
MkDir folderMonth
End If
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=folderMonth & "example.xlsx"
Application.DisplayAlerts = True
End Sub
uj5u.com熱心網友回復:
你檢查是否folder
存在,不folderYear
和/或folderMonth
。
嘗試
If Not fdObj.FolderExists(folderYear) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folderMonth) Then
MkDir folderMonth
End If
此外,您可能希望添加一個名為testing的檔案夾是否存在的檢查。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/468248.html