因此,我是使用access/VBA的新手,並且無法正常工作。如何將瀏覽的文本文件並將其放入列表框VBA
Private Sub Get_File_Click()
Dim fdlg As Office.FileDialog
Dim pipe_file As Variant
Dim FileName As String
Dim file As String
Dim fn As Integer
' Clear contents of listboxes and textboxes. '
Me.OrigFile.RowSource = ""
Me.ConvertFile.RowSource = ""
Me.FileName = ""
' Set up the File dialog box. '
Set fdlg = Application.FileDialog(msoFileDialogFilePicker)
With fdlg
.AllowMultiSelect = False
' Set the title of the dialog box. '
.Title = "Select pipe delimited file"
' Clear out the current filters, and then add your own. '
.Filters.Clear
.Filters.Add "Text Files", "*.txt"
' Show the dialog box. If the .Show method returns True, the '
' user picked a file. If the .Show method returns '
' False, the user clicked Cancel. '
If .Show = True Then
file = fdlg
fn = FreeFile
Open file For Input As #fn
Do While Not EOF(fn)
Line Input #fn, pipe_file
Me.OrigFile.AddItem pipe_file
Loop
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
這是我到目前爲止。 origFile是我試圖放入文本文件的列表框。 任何幫助表示讚賞 感謝
你有什麼特別的問題? – theninjagreg 2011-05-06 18:34:28