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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try using FileFormat:=xlExcel8 instead
 
Upvote 0
Try using FileFormat:=xlExcel8 instead
1717491081570.png
1717491112233.png
 
Upvote 0
Try renaming your variable fileName to something else eg fname or sFileName and do a find and replace on all except the save as line.
In save as it should appear with a capitalised F but it seems to be picking up the variable name.
 
Upvote 0
Try adding this line before the SaveAs line.
VBA Code:
ActiveWorkbook.CheckCompatibility = False
 
Upvote 0
Is there a reason for using the old .xls format?
 
Upvote 0
Is there a reason for using the old .xls format?

Would like to save at this directory: F:\Bring\Parcels\SA Sales\SA Customer Solutions B2B Parcels Express\Customer Logistics and Support DK
and just the active sheet - not the whole workbook as now
Still problem with "compatilibity" message
 
Upvote 0
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)
 
Upvote 0

Forum statistics

Threads
1,224,880
Messages
6,181,532
Members
453,054
Latest member
ezzat

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