SaveAs - Force filetype

trevolly

Board Regular
Joined
Aug 22, 2021
Messages
124
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm using this vba I've found to run a Save As box to open and point to a specific location on a network drive so the user only has to enter the filename they want to save the workbook as. It seems to default to a macro free workbook. Is there anyway of keeping this vba as it works but for it to force to save in .xlsm?

Thank you

VBA Code:
Sub SAVETOSUB()

ThisWorkbook.Save 'save current workbook in current name

With Application.FileDialog(msoFileDialogSaveAs)
AllowMultiSelect = False
.InitialFileName = "X:\Airfield Operations\2023 Airfield Inspection and Data\Aircraft High Powered Engine Runs\NEW\Pending Runs\"
If .Show = -1 Then .Execute
End With
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi all,

No replies to the above but after searching the web for days I found a solution.....thought I'd share the vba- it might help someone who wants to do the same.

Regards.

VBA Code:
Sub cmdSaveForm1_Click()

    Dim strFolder As String
    Dim i As Long
    Dim fname As String
    Dim reqdate As String

    'Find the position of the period in the file name
    i = InStr(ActiveWorkbook.Name, ".")
    fname = Range("C2")
    reqdate = Range("C6").Text
    

    'Create a default file name by concatenating the file name without the extention _
        plus the current date and time, and plus the xlsm extention
    Filename = Left(fname, i - 1) & " - " & (reqdate) & ".xlsm"

    'Open Save As dialog to a default folder with default file name
    With Application.FileDialog(msoFileDialogSaveAs)
        .AllowMultiSelect = False
        .FilterIndex = 2  '2 = xlsm
        .InitialFileName = "location" & Filename  '(replace location to your requirements)
        .InitialView = msoFileDialogViewDetails
        If .Show = -1 Then strFolder = .SelectedItems(1) Else Exit Sub
        .Execute
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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