Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
This code runs inside a template workbook. When the workbook opens it will check and see if the following workbook name exists, if not, it will create a saved workbook copy with that name, otherwise it will open that workbook. I am not sure if this matters, but this file is saved to OneDrive. The error 52 message occurs on this line:
and the syntax error occurs here: The following part of the code is highlighted in blue "C:\Users\"
VBA Code:
If Len(Dir(FilePath)) = 0 Then
VBA Code:
Set wb1 = ActiveWorkbook.SaveCopyAs "C:\Users\" & Environ("username") & "\OneDrive - CompanyName\Desktop\" & CurrMonth & "'s WO Report.xlsm"
VBA Code:
Dim wb1 As Workbook
Dim FilePath As String
CurrMonth = Format(DateAdd("M", 0, Now), "MMMM")
FilePath = ThisWorkbook.Path & "/" & CurrMonth & "'s WO Report.xlsm"
If Len(Dir(FilePath)) = 0 Then
Set wb1 = ActiveWorkbook.SaveCopyAs "C:\Users\" & Environ("username") & "\OneDrive - CompanyName\Desktop\" & CurrMonth & "'s WO Report.xlsm"
Else
Set wb1 = Workbooks.Open(FilePath)
End If
Set CheckForExistingWorkbooks = wb1
Last edited: