Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
Is there a way to save a Macro Workbook as .xlsx file? I found the following code online but when I open the converted .xlsx file, it tries to run the macros but then gives an error message "Sub function not defined" when sheet 1 is activated. This sheet does have code assigned to it. I don't want to set a password; all I want is for the user to ONLY view the file. Thanks.
VBA Code:
Sub BackupAsXLSX()
Dim swb As Workbook: Set swb = ThisWorkbook
Dim sFilePath As String: sFilePath = swb.FullName
Dim DotPosition As Long: DotPosition = InStrRev(sFilePath, ".")
Dim dFilePath As String: dFilePath = Left(sFilePath, DotPosition) & "xlsm"
Application.ScreenUpdating = False
swb.Sheets.Copy
Dim dwb As Workbook: Set dwb = ActiveWorkbook
Application.DisplayAlerts = False
dwb.SaveAs Filename:=dFilePath, FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
dwb.Close savechanges:=False
Application.ScreenUpdating = True
MsgBox "Excel Backup File Created with ( .xlsx) Extension.", vbInformation
End Sub