Code VBA "save as" keep debugging

Controltower

New Member
Joined
Jun 4, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
HI
I need a working code for:
Save current active sheet in a chosen folder and with a new filename
I need the window to pop up, where I can choose location and filename

Below string is keeping debugging...
.........

Sub SaveActiveSheetAsXLSWithDialog()
Dim SaveLocation As String
Dim fileName As String

' Show the Save As dialog to get the file name and location
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save Active Sheet As XLS"
If .Show = -1 Then
SaveLocation = .SelectedItems(1)
fileName = Dir(SaveLocation)

' Check if the file name has the ".xls" extension; if not, add it
If Right(fileName, 4) <> ".xls" Then
SaveLocation = SaveLocation & ".xls"
End If

' Save active sheet as XLS
ActiveSheet.SaveAs fileName:=SaveLocation, FileFormat:=xlWorkbookNormal
MsgBox "Sheet saved as XLS: " & SaveLocation, vbInformation, "Save As XLS"
Else
MsgBox "Operation canceled by user.", vbExclamation, "Save As XLS"
End If
End With
End Sub
 
That doesn't answer my question - is there a reason for using the old .xls format, rather than one of the newer formats? (that is the cause of the compatibility message)
No reason - just an old template used for the model - would like to use the new format - must I rewrite everything then?
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
No, just use the extension and format you want - eg xlsx for the extension and xlOpenXMLWorkbook for the file format.
 
Upvote 1
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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