If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Building Parsers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-22-04, 12:21
joshua310 joshua310 is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
Building Parsers

I will be working on building parsers soon that takes a file out of notepad (.txt) and imports it into excel.

My form will have a browse button, browse to file on your hard drive (a .txt) and then click open. Then on the form you will click the parse button and it will parse it out.

Whats the easiest way to do this? Can I manually parse it and then look at the code w/ alt+F11?
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 10:14
TerpInMD TerpInMD is offline
Registered User
 
Join Date: Jun 2004
Location: Terrapin Nation
Posts: 205
"Whats the easiest way to do this? Can I manually parse it and then look at the code w/ alt+F11?"









If you mean record a macro and then look at the code to modify it the answer would be no. The code wil show you how to browse for the file, thats about it.

You should consider using access. All you would have to do is import the file to a table.
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 11:13
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Quote:
Originally Posted by joshua310
My form will have a browse button, browse to file on your hard drive (a .txt) and then click open. Then on the form you will click the parse button and it will parse it out.
The easiest way to do this bit is to use the Application.GetOpenFile code
Once you get the text file you can use workbook.opentext
Search for these in the help file

Quote:
Originally Posted by joshua310
Whats the easiest way to do this? Can I manually parse it and then look at the code w/ alt+F11?
Depends if there is a consequitve delimiter or fixed width not if there is you can use the TextToColumns property on your selected range but without knowing more i won't be able to be of too much more help

David
Reply With Quote
  #4 (permalink)  
Old 07-26-04, 07:23
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Reading and pasing a file

Hi

Following on from DavidCotts couts suggestion I have listed below a modified extract I have written to do just what you have indicated.

This is based on a form having two command buttons and a text box (you will also need to show the form).

Code:
Option Explicit

Private Sub CommandButton1_Click()
    Dim File As String
     
    ChDir ThisWorkbook.Path
    File = Application.GetOpenFilename("Text Files (*.txt), *.txt", , "Select Text File")
    
    If File = "False" Then Exit Sub
    
    If Dir(File) = "" Then
        MsgBox File & " Not found !"
    Else
        TextBox1 = File
    End If

    
End Sub

Private Sub CommandButton2_Click()
    Dim Text As String
    
    If Dir(TextBox1) = "" Then
        MsgBox File & "File Path & Name must be specied !"
    Else
            
        Open TextBox1 For Input As #1 ' OPEN FILE FOR READING
                
        Line Input #1, Text ' READ FIRST LINE
        
        If Text <> "??" Then
            MsgBox "File not compatable etc"
        Else
            Do While Not EOF(FileNo)
                'PARSE EACH FILE LINE HERE AND WRITE TO ACTIVE SHEET !!
            Loop
        End If
    
        Close #1   'CLOSE FILE
    End If
End Sub

As indicated, information is available in the VBA Help files for both GetOpenFileName and the Open Method for reading a file on disk one line at a time.

Of course we do not know what procedure you require to parse each line.

This code also relies on the first line odf the file having a unique id to verifiy it is the correct type of file to be parsed!

Just one way of doing it!

HTH

MTB
Reply With Quote
  #5 (permalink)  
Old 07-26-04, 09:21
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Quote:
Originally Posted by MikeTheBike
Following on from DavidCotts couts suggestion I have listed below a modified extract I have written to do just what you have indicated.
2 tries and still you couldn't get it right, Ive been so short of time im starting to give more and more criptic answers

Joshuha post what some of yur text look like and how you want it parsed then we can look at ways of parsing it for you

David
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On