Excel VBA 日期保存 - 运行 时间错误 75 path/file 访问错误
Excel VBA Date Save - run time error 75 path/file access error
当我 运行 此代码允许我创建文件夹(如果它们不存在以将文件保存在其中)时,我收到以下错误消息:“运行 时间错误 75 path/file 访问错误
有什么想法吗?
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
你检查 folder
是否存在,而不是 folderYear
and/or folderMonth
.
尝试
If Not fdObj.FolderExists(folderYear) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folderMonth) Then
MkDir folderMonth
End If
此外,您可能希望添加一项检查,检查名为 testing 的文件夹是否存在。
当我 运行 此代码允许我创建文件夹(如果它们不存在以将文件保存在其中)时,我收到以下错误消息:“运行 时间错误 75 path/file 访问错误
有什么想法吗?
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
你检查 folder
是否存在,而不是 folderYear
and/or folderMonth
.
尝试
If Not fdObj.FolderExists(folderYear) Then
MkDir folderYear
End If
If Not fdObj.FolderExists(folderMonth) Then
MkDir folderMonth
End If
此外,您可能希望添加一项检查,检查名为 testing 的文件夹是否存在。