Changing File Format Causing Change in Location of Saved File

Chiznuggets

New Member
Joined
Jun 26, 2019
Messages
8
Hello friends,

I'm trying to save an Excel file with VBA code to the location C:\Users\Work\Desktop\Google Drive.

I am able to successfully do this with
Code:
ActiveWorkbook.SaveAs ("C:\Users\Work\Desktop\Google Drive\" & varEventName & " " & varDate & " " & varReportType & ".xlsx")

However when I go to change the file format with
Code:
ActiveWorkbook.SaveAs FileFormat:=51
the saved file location changes to a different location, C:\Users\Work\Desktop\June Monthly Reports.

Any thoughts on how to fix this problem?

Just to be clear I know the second line of code that I provided is the problem because I stepped through the code one line at a time.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try it all on one line:
Code:
ActiveWorkbook.SaveAs ("C:\Users\Work\Desktop\Google Drive\" & varEventName & " " & varDate & " " & varReportType & ".xlsx"), FileFormat:=51
 
Upvote 0
Not usre why you're doing it twice, why not just
Code:
ActiveWorkbook.SaveAs "C:\Users\Work\Desktop\Google Drive\" & varEventName & " " & varDate & " " & varReportType & ".xlsx", 51
 
Upvote 0
Thank you for the quick replies.

The reason I don't have it all in one line is that I would like to change the name of the sheet. Here is how I have the code organized currently
Code:
ActiveWorkbook.SaveAs ("C:\Users\Work\Desktop\Google Drive\" & varEventName & " " & varDate & " " & varReportType & ".xlsx")

    
ActiveSheet.Name = ActiveSheet.Range("m2")
Columns("K:N").Select
Selection.EntireColumn.Delete




Range("a1").Select


ActiveWorkbook.SaveAs FileFormat:=51

This is how I've made the code change the name of the file and then change the sheet name separately.
 
Upvote 0
As you are not changing the name of the file or it's location, then change the sheet name & delete the columns first.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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