Simple VBA CopyAs

hellovaras

New Member
Joined
Feb 2, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a very basic question. I want the below macro to output an xlsx file, not a macro file. I have tried changing the extension and the FileFormat but the copied file does not open. I get a message that the file types are different. Any and all assistance is appreciated. TIA

Sub Workbook_SaveUp()

Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:="\\XXXvvfile1\market_XXXXX\XXX \Reporting Analyst\Test_File_JLV.xlsm" <- it only works when I use the xlsm extension. Otherwise, the new SaveAs workbook wont open.
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You can simply make a copy of the workbook, save it in the desired format, and then close it, like this . . .

VBA Code:
Sub Workbook_SaveUp()

    Application.DisplayAlerts = False
    ActiveWorkbook.Sheets.Copy
    With ActiveWorkbook
        .SaveAs Filename:="\\XXXvvfile1\market_XXXXX\XXX \Reporting Analyst\Test_File_JLV.xlsx", FileFormat:=51
        .Close
    End With
    Application.DisplayAlerts = True

End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

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