我已经编写了以下代码来尝试打开文件浏览器,然后将文件位置保存到文本框中。到目前为止,我可以打开文件浏览器,但无法将其保存到我的文本框
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 :(得分: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