![]() |
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! |
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! |
All times are GMT +1. The time now is 04:38 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com