2014-07-10 86 views
0

我已經寫下了以下代碼,用於嘗試打開文件瀏覽器,然後將文件位置保存到文本框中。到目前爲止,我可以打開文件瀏覽器,但不能讓它的路徑保存到我的文本框中如何在對話框瀏覽器的文本框中保存文件位置

Private Sub txtImageName_Click() 
    Dim f As Object 
    Dim strFile As String 
    Dim strFolder As String 
    Dim varItem As Variant 

    Set f = Application.FileDialog(3) 
    f.AllowMultiSelect = True 
    If f.Show Then 
    For Each varItem In f.SelectedItems 
     strFile = Dir(varItem) 
     strFolder = Left(varItem, Len(varItem) - Len(strFile)) 
     MsgBox "Folder: " & strFolder & vbCrLf & _ 
      "File: " & strFile 
    Next 
    End If 
    Set f = Nothing 
End Sub 

回答

0

要保存文件夾和文件到一個文本框:

Private Sub txtImageName_Click() 
    Dim f As Object 
    Dim strFile As String 
    Dim strFolder As String 
    Dim varItem As Variant 

    Set f = Application.FileDialog(3) 
    f.AllowMultiSelect = True 
    If f.Show Then 
    For Each varItem In f.SelectedItems 
     strFile = Dir(varItem) 
     strFolder = Left(varItem, Len(varItem) - Len(strFile)) 
     MsgBox "Folder: " & strFolder & vbCrLf & _ 
      "File: " & strFile 
     Me.YourTextbox = strFolder & "\" & strFile <<<<<<<<<<<<<<<< ADD THIS LINE 
    Next 
    End If 
    Set f = Nothing 
End Sub 
+0

這是真棒謝謝。 – Alex

相關問題