Macro to save as an .xlsx file

cgclower

New Member
Joined
Feb 28, 2010
Messages
40
Hello!
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I am trying to write a macro that takes an (already open) .xlsm file and saves it as a .xlsx file with the same name plus “FROZEN – “ at the beginning. My code currently is:
<o:p></o:p>
Code:
ActiveWorkbook.SaveAs Filename:="FROZEN - " & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5), FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
<o:p></o:p>
I am running into 2 problems.
<o:p></o:p>
1. The file only saves in the “My Documents” folder. I want it to save in the same folder as the original file. My understanding was this would automatically happen with the .SaveAs method if no other path was specified, but that isn’t happening.
<o:p></o:p>
2. When attempting to close the new .xlsx file, my BeforeClose macros are still running. Since a .xlsx file should have no macros, I don’t know why this is happening. It is a problem because my BeforeClose macro hides a bunch of tabs that I need visible in the new file format.
<o:p></o:p>
Help?
<o:p></o:p>
Thank you!!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Maybe like this

Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\FROZEN - " & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5), FileFormat:=xlOpenXMLWorkbook
Application.EnableEvents = False
ActiveWorkbook.Close
Application.EnableEvents = True
 
Upvote 0
Maybe like this

Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\FROZEN - " & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5), FileFormat:=xlOpenXMLWorkbook
Application.EnableEvents = False
ActiveWorkbook.Close
Application.EnableEvents = True

I used this code to save as to xlsx. I run a macro and at the end I added this code to save as and close. While using your code to save as to xlsx, the number from the filename is not getting added to the new file created. For example, The file DCS2.csv will save as to DCS.xlsx. Can you please give me a solution for this?
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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