Changing from .CSV file type to .xlsx with VBA

BYahr

New Member
Joined
Jul 12, 2023
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I have the code below to save the current file as an .xlsx file, but when I try to re-open the file, I get a file type error. It appears to be saving the document as an .xlsx file but it truly is staying in the .csv file type which was originally downloaded which Excel cannot access.

What I ultimately want is to have the document changed from .csv to .xlsx file type in a user defined location with the given file name and the date. The date is available in the file and is the day prior to the current date. Example: Trial save mm.dd.yyyy The date needed is located in cell E5 of the document.

Below is the code as it stands currently. I must remember to then save as again to change from .csv to .xlsx.

Dim path As Variant


path = Application.GetSaveAsFilename( _
Title:="Select a File Location", _
InitialFileName:="Trial save", _
FileFilter:="Excel Files, *.xlsx")


If path = False Then
MsgBox "No Loction Selected!", 16
Else

ActiveWorkbook.SaveAs path

End If
 

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.
Try specifying the file format . . .

VBA Code:
ActiveWorkbook.SaveAs path, 51 'xlOpenXMLWorkbook

Or, with named arguments...

VBA Code:
ActiveWorkbook.SaveAs  Filename:=path, FileFormat:=51

Hope this helps!
 
Upvote 0
Solution
At my first attempt the top suggestion appears to be successful. Thanks for the assist.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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