Save As Non Macro Enabled Worksheet-VBA

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
I was trying to create a macro that when I open a workbook that is macro-enabled I could simply run some code that will change it to an xls or xlsx and save it as the current file name. I need it to save it to its current location. Thanks as always
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
How about
Code:
Sub bamaisgreat()
   With ActiveWorkbook
      Application.DisplayAlerts = False
      .SaveAs Replace(.FullName, ".xlsm", ""), 51
      Application.DisplayAlerts = True
   End With
End Sub
 
Upvote 0
Thank you for the help. I failed to mention one thing. Can you make it where it will kill the old file??
 
Upvote 0
How about
Code:
Sub bamaisgreat()
   Dim fname As String
   With ActiveWorkbook
      Application.DisplayAlerts = False
      fname = .FullName
      .SaveAs Replace(.FullName, ".xlsm", ""), 51
      Application.DisplayAlerts = True
   End With
   Kill fname
End Sub
 
Upvote 0
Worked perfect. I promise this is my last request. There are some people that will be using this that dont know the different type file extensions.
Is there something that could be added so if the workbook is already an xls that it want throw up an error?
 
Upvote 0
This will work regardless of the extension, a long as you don't have any . as part of the file name.
 
Upvote 0
I tried running the macro on the workbook after I had already changed it to an XLS and a VBA message pops up that says runtime error 70 permission denied. I dont have a the workbook password protected so im not sure why this is popping up.
 
Upvote 0
Apologies for the late reply, this must have slipped through the net.
How about
Code:
Sub bamaisgreat()
   Dim fname As String
   With ActiveWorkbook
      If ActiveWorkbook.FileFormat = 52 Then
         Application.DisplayAlerts = False
         fname = .FullName
         .SaveAs Replace(.FullName, ".xlsm", ""), 51
         Application.DisplayAlerts = True
      End With
   End With
   Kill fname
End Sub
 
Last edited:
Upvote 0
Thanks for your help. I am getting an error with this at the "End With"
 
Upvote 0
There's a typo, it should be
Code:
Sub bamaisgreat()
   Dim Fname As String
   With ActiveWorkbook
      If ActiveWorkbook.FileFormat = 52 Then
         Application.DisplayAlerts = False
         Fname = .FullName
         .SaveAs Replace(.FullName, ".xlsm", ""), 51
         Application.DisplayAlerts = True
     [COLOR=#ff0000] End If[/COLOR]
   End With
   Kill Fname
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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