View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Brian Brian is offline
external usenet poster
 
Posts: 17
Default Code for bring up the file-open dialog box

this might be of use, its from the post about how to parse a text file ....
it has a open file (incl a filter for text files!), you should be able to
strip out the useful bits...

Brian

Tom Ogilvy wrote:

Sub testme2()
Dim FName As String
Dim FNum As Long
Dim sLine As String
Dim TName As Variant

TName = Application.GetOpenFilename _
(fileFilter:="Text Files (*.txt),*.txt,All Files (*.*),*.*", _
Title:="Open Report")
If TName = False Then
MsgBox "You didn't select a file"
'Exit Sub
Cleanup
End
End If

FName = CStr(TName)

FNum = FreeFile

Open FName For Input As FNum
Do While Not EOF(FNum)
Input #FNum, sLine
If InStr(1, sLine, "NUE00001 GRAND TOTALS", _
vbTextCompare) 0 Then
Line Input #FNum, sLine 'Match where next line is needed
Cells(3, 3).Value = sLine
ElseIf InStr(1, sLine, "NUE00002 GRAND TOTALS", _
vbTextCompare) 0 Then
Line Input #FNum, sLine
Line Input #FNum, sLine 'Match where line 2 down is needed
Cells(4, 3).Value = sLine
End If
Loop
' now close the file
Close #FNum
End Sub

"Ben" wrote in message
...
Hi all,

Please share with me the code to simulate the File-Open dialog box in
VBA. Thanks so much.

Ben

--