Hello,
Briefly I created a macro that saves my workbook as two versions--a macro enabled version and a non-macro enabled version.
The macro works correctly.
HOWEVER, it crashes my excel every time I run it.
Also as a background, my code saves the second workbook as the same name but with "DASHBOARD" added to the title. Hence the IF statement in my code.
Really what i'm looking for is a fix to the crashing and why my small brain cannot figure it out. I believe it has something to do with this line--wb.SaveAs (Path & WorkbookName).
Cheers!
Briefly I created a macro that saves my workbook as two versions--a macro enabled version and a non-macro enabled version.
The macro works correctly.
HOWEVER, it crashes my excel every time I run it.
Also as a background, my code saves the second workbook as the same name but with "DASHBOARD" added to the title. Hence the IF statement in my code.
Really what i'm looking for is a fix to the crashing and why my small brain cannot figure it out. I believe it has something to do with this line--wb.SaveAs (Path & WorkbookName).
Cheers!
Code:
Sub SaveWorkbook()
Dim wb As Workbook, wb2 As Workbook
Dim Path As String
Dim WorkbookName As String
WorkbookName = ActiveWorkbook.Name
Application.DisplayAlerts = False
Path = "C:\Users\" & Environ("Username") & "\Documents\"
Set wb = ThisWorkbook
wb.SaveAs (Path & WorkbookName)
If InStr(WorkbookName, ".") > 0 Then
WorkbookName = Left(WorkbookName, InStr(WorkbookName, ".") - 1)
End If
Set wb2 = Workbooks.Open(Path & WorkbookName)
wb2.SaveAs Path & WorkbookName & " " & "DASHBOARD.xlsx", xlOpenXMLWorkbook
wb2.Close
Application.DisplayAlerts = True
End Sub
Last edited: