Save as dialog box defaulted to XLSM

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I'd like a macro that when i run it it opens the save as dialog box and defaults to XLSM

the file name is in activesheet "D17" and is written as just the name so "Tony Test1" for example,
so i'd like the dialog box to have "Tony Test 1" in the save as name area and XLSM but everything I try give me XLSX
some of the file are being converted from XLSX to XLSM please help if you can.

I've attached the code I use, but feel free to give me your own if you wish

Heres my code:

VBA Code:
Sub SaveAs1()
    Dim ws As Worksheet
    Dim fileName As String
    Dim saveAsDialog As FileDialog
    Dim savePath As Variant

    Set ws = ThisWorkbook.ActiveSheet

    fileName = ws.Range("F17").Value

    Set saveAsDialog = Application.FileDialog(msoFileDialogSaveAs)
 
    saveAsDialog.Title = "Please choose location to save this document"
    
        If InStrRev(fileName, ".xlsm") = 0 Then
        fileName = fileName & ".xlsm"
        End If
    
    saveAsDialog.InitialFileName = fileName

    If saveAsDialog.Show = -1 Then

        savePath = saveAsDialog.SelectedItems(1)
        ThisWorkbook.SaveAs fileName:=savePath
        MsgBox "Document has been saved"
        ws.Range("D19").Value = "Saved"
        
        
       Call RoleM_show
       MsgBox "You can now start building the Role Matrix data.", , ""
        
    Else

        MsgBox "Document not saved!"
    End If
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Maybe...
VBA Code:
Application.Dialogs(xlDialogSaveAs).Show "Tony Test1", 52
 
Upvote 0
Thanks mark, what am i supposed to do with this were does it go? sorry if it obvious just could see it
Thanks
Tony
 
Upvote 0
Try replacing

VBA Code:
fileName = ws.Range("F17").Value

    Set saveAsDialog = Application.FileDialog(msoFileDialogSaveAs)
 
    saveAsDialog.Title = "Please choose location to save this document"
   
        If InStrRev(fileName, ".xlsm") = 0 Then
        fileName = fileName & ".xlsm"
        End If
   
    saveAsDialog.InitialFileName = fileName

with

VBA Code:
saveAsDialog = Application.GetSaveAsFilename( _
    FileFilter:="Macro-Enabled Workbook (*.xlsm), *xlsm", InitialFileName:="Tony Test1", Title:="Please choose location to save this document")

change
VBA Code:
Dim saveAsDialog As FileDialog
to
VBA Code:
Dim saveAsDialog
 
Last edited:
Upvote 0
Just to clarify (adapt the rest of your code to your needs, including removing the Exit Sub line)....

VBA Code:
    Dim saveAsDialog

    saveAsDialog = Application.GetSaveAsFilename( _
                   FileFilter:="Macro-Enabled Workbook (*.xlsm), *xlsm", InitialFileName:="Tony Test1", Title:="Please choose location to save this document")
      
    If saveAsDialog <> False Then
        ActiveWorkbook.SaveAs fileName:=saveAsDialog, FileFormat:=52
        Exit Sub
    End If
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

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