Controltower
New Member
- Joined
- Jun 4, 2024
- Messages
- 5
- Office Version
- 365
- Platform
- 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
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