简体   繁体   English

另存为提示位置但使用单元格中的文件名

[英]Save As To Prompt For Location But Use Filename From Cell

I got this code from a forum and it works but I need to tweak it to show me the "save as" box but I with the name already populated with my variable FName.我从论坛上得到了这段代码,它可以工作,但我需要调整它以显示“另存为”框,但我的名称已经填充了我的变量 FName。

Can someone help me with this?有人可以帮我弄这个吗?

Sub Save_New()
Dim FName As String
Dim FPath As String
'FPath = "C:"
FName = Sheets("Sheet1").Range("A1").Text
ThisWorkbook.SaveAs Filename:=FName
End Sub

You can use the Application.GetSaveAsFilename method for that …您可以使用Application.GetSaveAsFilename 方法...

Option Explicit

Sub Save_New()
    Dim FName As String
    FName = Sheets("Sheet1").Range("A1").Text

    Dim DialogResult As Variant 'variant is needed because the dialog returns FALSE if users presses cancel.
    DialogResult = Application.GetSaveAsFilename(InitialFilename:=FName)

    If Not DialogResult = False Then
        ThisWorkbook.SaveAs Filename:=DialogResult
    Else
        'user clicked cancel
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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