+ Reply to Thread
Results 1 to 2 of 2

Thread: Modifying .txt file using Excel VBA

  1. #1
    Chandee3
    Guest

    Modifying .txt file using Excel VBA

    Hi there.

    I am using excel VBA to launch another software using a journal file (which
    is a text file). However, before I launch I sometimes want to modify some of
    the information in the text file. I have written some VBA code to read the
    original journal file and then printing a new text file at the same time.
    When certain variables are read in I substitute the value that is printed in
    the new file. This all works well and below is an example of my code.

    Open filename For Input Access Read As #2
    Open tempfile For Output As #3

    While Not EOF(2)

    Input #2, slask

    If slask = "; Zero Shear Visc visc0" Then
    Print #3, slask
    Input #2, slask
    Print #3, visc0_1
    'Print #3, ";;;"
    Input #2, slask
    End If


    If slask = "; Inf Shear Visc viscinf" Then
    Print #3, slask
    Input #2, slask
    Print #3, viscinf1
    Input #2, slask
    End If

    Print #3, slask
    Wend

    'Print #3, ";;;"
    Close #2
    Close #3

    Name filename As filenamenew
    Name tempfile As filename

    I am very new at this so I am not really sure how the input and output
    works, but I have found that using this method the new file that is printed
    leaves out some vital characters such as ". I am reading in the word
    "laminar" from the input file but the printed output reads laminar without
    the ". Unfortunately I really need my " to be printed to the for the journal
    file to work as it should. Any suggestions?

    Thank you!

  2. #2
    Tom Ogilvy
    Guest

    RE: Modifying .txt file using Excel VBA

    if you want to include a double quote within a string, you need to double the
    double quote. So to get "Laminar"

    s = """laminar"""
    ? s
    "laminar"

    (demo'd from the immediate window)

    --
    Regards,
    Tom Ogilvy


    "Chandee3" wrote:

    > Hi there.
    >
    > I am using excel VBA to launch another software using a journal file (which
    > is a text file). However, before I launch I sometimes want to modify some of
    > the information in the text file. I have written some VBA code to read the
    > original journal file and then printing a new text file at the same time.
    > When certain variables are read in I substitute the value that is printed in
    > the new file. This all works well and below is an example of my code.
    >
    > Open filename For Input Access Read As #2
    > Open tempfile For Output As #3
    >
    > While Not EOF(2)
    >
    > Input #2, slask
    >
    > If slask = "; Zero Shear Visc visc0" Then
    > Print #3, slask
    > Input #2, slask
    > Print #3, visc0_1
    > 'Print #3, ";;;"
    > Input #2, slask
    > End If
    >
    >
    > If slask = "; Inf Shear Visc viscinf" Then
    > Print #3, slask
    > Input #2, slask
    > Print #3, viscinf1
    > Input #2, slask
    > End If
    >
    > Print #3, slask
    > Wend
    >
    > 'Print #3, ";;;"
    > Close #2
    > Close #3
    >
    > Name filename As filenamenew
    > Name tempfile As filename
    >
    > I am very new at this so I am not really sure how the input and output
    > works, but I have found that using this method the new file that is printed
    > leaves out some vital characters such as ". I am reading in the word
    > "laminar" from the input file but the printed output reads laminar without
    > the ". Unfortunately I really need my " to be printed to the for the journal
    > file to work as it should. Any suggestions?
    >
    > Thank you!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0