简体   繁体   中英

Open save window in file path from cell and populate filename from cell

I need a simple code that will open the save window in a file location from a cell and also populate the file name from a cell, leaving the save window open so you can edit the path or filename before you click save if need be

I'm using this code but it only populates the filename

Application.Dialogs(xlDialogSaveAs).Show Range("A3").Text & "- (Submittal)" & ".xlsx"

I would like it to also open the save window in a file path from cell "A2"

在此处输入图片说明

Also i don't know if it matters but this will be ran on a workbook that has never been saved before

This will get filename from Cell A1 and Path from Cell A2 both on Sheet(1) . Ensure that the path is in the format C:\\Users\\name\\ remembering to ensure there is a backslash \\ after the path.

Sub SaveAs()
Dim fPth As Object
Dim Path As String
Path = Sheets(1).Range("A2").Text
fileName = Sheets(1).Range("A1").Text
Set fPth = Application.FileDialog(msoFileDialogSaveAs)

        With fPth
            .InitialFileName = Path & fileName & ".xlsx"
            .Title = "Save your File"
            .InitialView = msoFileDialogViewList
            .Show
        End With

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM