如何在excel VBA中获取已保存文件的路径和名称?

时间:2021-05-01 15:37:51

I am using the following code to save the file but i am not able to get the saved file path and name .

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

Is there a way to get those details?

有没有办法获得这些细节?

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

1 个解决方案

#1


0  

Try using Application.GetSaveAsFilename. Create a Variant variable, and set that to Application.GetSaveAsFilename after you save it.

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

#1


0  

Try using Application.GetSaveAsFilename. Create a Variant variable, and set that to Application.GetSaveAsFilename after you save it.

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