2012-04-30 56 views
6

選定的文件名這是我的代碼,我想知道如何得到的文件名選擇的MS Access獲得從FileDialog的

Dim f As Object 
Set f = Application.FileDialog(3) 
f.AllowMultiSelect = True 
If f.Show Then 
    For i = 1 To f.SelectedItems.Count 
     MsgBox f.SelectedItems(i) 
    Next 
EndIf 

回答

10

你的意思是這樣嗎?

Sub Sample() 
    Dim f As Object 

    Set f = Application.FileDialog(3) 

    f.AllowMultiSelect = True 

    If f.Show Then 
     For i = 1 To f.SelectedItems.Count 
      MsgBox Filename(f.SelectedItems(i)) 
     Next 
    End If 
End Sub 

Public Function Filename(ByVal strPath As String) As String 
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then 
     Filename = Filename(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1) 
    End If 
End Function