Over My Head... Trying to open "Saveas" and prefill name based on Concat cell.

Brassaxe

New Member
Joined
Aug 6, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I am trying to have Excel open a save as and prefill the name based on a concat cell, but NOT prefill the location.
I am good with excel but the VBA is going over my head. This is what I have

Sub SaveFile()
Dim NameFile As Variant
With Worksheets("Settings")
NameFile = .Range("X2") & ".xlsm"
End With
ThisWorkbook.SaveAs FileName:=NameFile
End If
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
In order to save the workbook, you need to include a location. Do you want the macro to ask you to select a location?
 
Upvote 0
In order to save the workbook, you need to include a location. Do you want the macro to ask you to select a location?
Do I need to define or have defined the location to input the name in the dialog? Can it just open the dialog box, prefill the name, and let me define the location from there?

I wish I knew what I was doing I tried assembling the above code from what I could find online. I'm not good at it yet.
 
Upvote 0
I would suggest that the easiest way would be to first select the destination folder and then save the file based on X2. Please advise.
 
Upvote 0
That may become complicated as multiple users will be using this base .xlsm as the template to save it's completed form to their own defined locations. But you say you can have it prompt for a location?
???
 
Upvote 0
Yes, I can have it prompt for a location if that will work for you.
 
Upvote 0
Try:
VBA Code:
Sub SaveFile()
    Application.ScreenUpdating = False
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            sPath = .SelectedItems(1)
            ActiveWorkbook.SaveAs FileName:=sPath & Application.PathSeparator & Sheets("Settings").Range("X2") & ".xlsm", FileFormat:=52
        End If
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Allows the folder selection ,then is says

Run-time error '1004':
Method "SaveAs' of object '_Workbook' failed

Flags this line

ActiveWorkbook.SaveAs FileName:=sPath & Application.PathSeparator & Sheets("Settings").Range("X2") & ".xlsm", FileFormat:=52
 
Upvote 0

Forum statistics

Threads
1,215,880
Messages
6,127,523
Members
449,385
Latest member
KMGLarson

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