vba Binary code to read text file & search particular word & amount associated with

  • Hi Team,


    Could you please advise how to read a text file in binary & search a particular word in text file and copy that word & amount associated with if found.


    I have attached one text file wherein i have used some dummy line.


    If name Rahaman found in text file then binary code should copy both name & amount to the excel sheet.


    Kindly advise.


    Thanks in advance for the help.


    Regards,
    Rahaman.

  • Re: vba Binary code to read text file & search particular word & amount associated wi


    Code
    Sub M_snb()
        Open "G:\OF\0_raha.txt" For Binary As #1
            MsgBox Join(Filter(Split(Input(LOF(1), 1), vbCrLf), "Raha"), vbLf), , "snb"
        Close
    End Sub
  • Re: vba Binary code to read text file & search particular word & amount associated wi


    You don't have a binary file however you can open a text file for Binary Access as snb has done (or Sequential/Random access). As cytop said you either have a binary file or a text file - they are NOT the same thing. There are certain advantages to binary files which you can find with Google. Why you want this opened for binary access I do not know. To do what you want you can open the text file and test each line to see if your name is present then use a regular expression to write out the results. See attached workbook. I have only used a very basic regular expression pattern however again Google is your friend is you want to be more specific wrt currency format.

    Files

    Regards
    [SIZE=3]Anthony
    [/SIZE]&WCF_AMPERSAND[SIZE=3]
    [/SIZE]&WCF_AMPERSAND&WCF_AMPERSAND&WCF_AMPERSAND[SIZE=2]You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.[/SIZE]




  • Re: vba Binary code to read text file & search particular word & amount associated wi


    Quote from smuzoen;699561

    You don't have a binary file however you can open a text file for Binary Access as snb has done (or Sequential/Random access). As cytop said you either have a binary file or a text file - they are NOT the same thing. There are certain advantages to binary files which you can find with Google. Why you want this opened for binary access I do not know. To do what you want you can open the text file and test each line to see if your name is present then use a regular expression to write out the results. See attached workbook. I have only used a very basic regular expression pattern however again Google is your friend is you want to be more specific wrt currency format.




    Hi Sir,


    Thank you very much for helping me.


    The codes are working fine as i expected.


    I understood the things you advised in the post & will refer the link you provided as more suggestions.


    Once again thank you for everything.


    Regards,
    Rahaman.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!