从FileDialog获取的string不显示在消息框中

我试图用下面的代码显示一个文件保存在消息框中的位置:

Sub export() Dim MyPath As String Dim MyFileName As String MyFileName = "MyFileName" Worksheets("Tab").Copy With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Select a Folder" .AllowMultiSelect = False .InitialFileName = "Path" If .Show = -1 Then GoTo Nextcode1 Else GoTo Nextcode2 End If MyPath = .SelectedItems(1) & "\" End With Nextcode1: Block of codes that deals with existing file name. GoTo Nextcode3 Nextcode2: Block of codes that deals with cancel. GoTo Nextcode4 NextCode3: Application.DisplayAlerts = False With ActiveWorkbook .SaveAs fileName:=MyPath & MyFileName, FileFormat:=xlCSV, CreateBackup:=False .Close False End With Application.DisplayAlerts = True Worksheets("OtherTab").Activate MsgBox ("The tab has been exported to " & MyPath & MyFileName & ".") GoTo NextCode4 NextCode4: End Sub 

但是,仅显示消息框

 The tab has been exported to MyFileName. 

与MyPath完全省略。 我试了下面的代码

 PathName = MyPath & MyFileName MsgBox ("The tab has been exported to " & PathName & ".") 

 Cstr(MyPath) MsgBox ("The tab has been exported to " & MyPath & MyFileName & ".") 

无济于事。 我怀疑是从msoFileDialogFolderPicker获得的path名不是一个string对象,但我不知道如何处理它。 帮助表示赞赏!

好吧,我的坏。 该

 MyPath = .SelectedItems(1) & "\" 

行应该已经下了

 If .Show = -1 Then