Save sheet without macro's

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
91
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hello All,

I have a excel macro that is saved on a notepad text file to use i copy and paste this into the excel sheet in question.

When the code is run at the end of the macro i would like the sheet to save as a .xls without a warning.
i found a thread here, that works ok,


Private Sub savecopynomacros()

ThisWorkbook.Save ' save any unsaved changes
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & Replace(ThisWorkbook.Name, ".xlsm", "") & " no macros", FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
'ThisWorkbook.Close

End Sub

however this creates another file i would like to just save the file that is open with the same name.
I am not sure how to modify the code as it adds a bit to the file name and changes the file type.

when i delete this part of code

& " no macros", FileFormat:=xlOpenXMLWorkbook

i get Error 1004 "Application-defined or Object-defined error"


I am using office 363 & office 2021

Regards

Steve
 
Try this. Note the Kill line (commented out) deletes the original .xlsm file.

VBA Code:
Public Sub Save_Workbook_As_xlsx()
       
    Dim p As Long, xlsm As String
    xlsm = ThisWorkbook.FullName
    p = InStrRev(xlsm, ".")
    Application.DisplayAlerts = False
    ThisWorkbook.SaveAs Left(xlsm, p) & "xlsx", xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    Application.Quit
    'Kill xlsm
    ThisWorkbook.Close False
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,226,771
Messages
6,192,919
Members
453,767
Latest member
922aloose

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top