dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I discovered some VBA to be able to save a workbook with a custom filename that contains date and time stamp.
My goal is just to save the file as *.xlsx.
The code below works in regards to saving the workbook with the bespoke filename; however, when you try and open the workbook, the following error message results:
Would anybody be willing to regarding what is wrong with the last sub outlining the extension that would cause this error?
Kind regards,
Doug.
I discovered some VBA to be able to save a workbook with a custom filename that contains date and time stamp.
My goal is just to save the file as *.xlsx.
The code below works in regards to saving the workbook with the bespoke filename; however, when you try and open the workbook, the following error message results:
Excel cannot open the file 'order-details-export_200190517-1627 Orders Importer.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and the file exension matches the format of the file'
Code:
[B]Public Sub SaveFileAs()[/B]
Dim TodaysDate As String
Dim RawDataFileName As Variant
Dim SaveFileName As Variant
Dim SavePath As Variant
Dim SavePathAndFileName As Variant
TodaysDate = GetTodaysDate
SaveFileName = "order-details-export_" & TodaysDate & " Orders Importer"
SavePath = "C:\Users\username\Desktop"
SavePathAndFileName = SavePath & "\" & SaveFileName
SaveWorkbookAs (SavePathAndFileName)
[B]End Sub[/B] [COLOR=#006400]'SaveFileAs
[/COLOR]
[B]Private Function GetTodaysDate()[/B]
GetTodaysDate = Format(Now(), "yyyymmdd-hhmm")
[B]End Function[/B] [COLOR=#006400]'GetTodaysDate[/COLOR]
[B]Private Sub SaveWorkbookAs(SaveFileName As String)[/B]
Dim FileExtension As String
Dim SaveFile As String
FileExtension = "Excel Workbook (*.xlsx), *.xlsx," & _
"All files (*.*), *.*"
SaveFile = Application.GetSaveAsFilename( _
InitialFileName:=SaveFileName, _
FileFilter:=FileExtension)
MsgBox "Save File is called " & SaveFile
ActiveWorkbook.SaveAs SaveFile, xlWorkbookNormal
[B]End Sub[/B] [COLOR=#006400]'SaveWorkbookAs[/COLOR]
Would anybody be willing to regarding what is wrong with the last sub outlining the extension that would cause this error?
Kind regards,
Doug.