【问题标题】:How to get path and name of the saved file in excel VBA?如何在excel VBA中获取保存文件的路径和名称?
【发布时间】:2015-07-24 16:57:47
【问题描述】:

我正在使用以下代码保存文件,但我无法获取保存的文件路径和名称。

有没有办法获取这些详细信息?

Sub Test3()

On Error Resume Next
Dim FileSelected As String
Dim strPath As String

FileSelected = Application.Dialogs(xlDialogSaveAs).Show

If Not FileSelected <> "False" Then
MsgBox "You have cancelled"
Exit Sub
End If

If FileSelected <> "False" Then
strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)
    'displays the result in a message box
Call MsgBox(strPath, vbInformation, "Save Path")
Exit Sub
End If

End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    尝试使用Application.GetSaveAsFilename。创建一个Variant 变量,并在保存后将其设置为Application.GetSaveAsFilename

    【讨论】:

      猜你喜欢
      • 2010-12-26
      • 1970-01-01
      • 2017-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多