Create a Save as dialogue box

Armadillos

New Member
Joined
Apr 25, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi

I am looking to create a Save As dialogue box in VBA. I simply want to recreate the window that you get if your choose Save As from the File Menu, i.e. it has the the same file name as the existing file in File name:' box (so it can be slightly altered manually) and the same file type in the 'Save as type:' box.

Thanks in advance
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try the following...

VBA Code:
Sub test()

    Dim fileFilter As String
    Dim fileFormat As String
    Dim saveAsFileName As Variant
    
    Select Case ActiveWorkbook.fileFormat
        Case 51
            fileFilter = "Excel Workbook (*.xlsx), *.xlsx"
            fileFormat = xlOpenXMLWorkbook
        Case 52
            fileFilter = "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm"
            fileFormat = xlOpenXMLWorkbookMacroEnabled
    End Select
    
    saveAsFileName = Application.GetSaveAsFilename( _
        InitialFileName:=ActiveWorkbook.Name, _
        fileFilter:=fileFilter, _
        Title:="Save As", _
        ButtonText:="Save")
        
    If saveAsFileName = False Then Exit Sub
    
    ActiveWorkbook.SaveAs Filename:=saveAsFileName, fileFormat:=fileFormat

Note that you can amend the Select Case statement to include other file formats.

Hope this helps!
 
Last edited:
Upvote 0
Hi again

Sorry, I've noticed one issue. Whilst it is saving the new file (lets say Rev 2) as required, the workbook that is still open in excel, is the earlier version (Rev 1). Is it possible for the open workbook to be the latest version that has been saved.
 
Upvote 0
Sorry, my mistake, while we prompted the user for the SaveAs filename, we didn't actually save the workbook. I've edited my post to make this correction.

Hope this helps!
 
Upvote 0
Hi

I am looking to create a Save As dialogue box in VBA. I simply want to recreate the window that you get if your choose Save As from the File Menu, i.e. it has the the same file name as the existing file in File name:' box (so it can be slightly altered manually) and the same file type in the 'Save as type:' box.

Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,616
Members
449,238
Latest member
wcbyers

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