tag:blogger.com,1999:blog-28492262.post8164385558317643254..comments2023-12-27T22:22:25.151-08:00Comments on VBA Tips & Tricks: VBA Read Text Files (With Leading & Trailing Spaces)Unknownnoreply@blogger.comBlogger17125tag:blogger.com,1999:blog-28492262.post-53072503179446447492014-04-25T01:07:32.338-07:002014-04-25T01:07:32.338-07:00This article has code to open, read and write text...This article has code to open, read and write text files and also to merge multiple text files to one single text file. Hope the commands in this article helps for your purpose. <br />http://officetricks.com/merge-multiple-files-to-one-file/<br />Anonymoushttps://www.blogger.com/profile/17314292996839809606noreply@blogger.comtag:blogger.com,1999:blog-28492262.post-75753122289331181182013-06-21T00:29:54.635-07:002013-06-21T00:29:54.635-07:00use a counter
line=1
Do Until oFS.AtEndOfStream
sT...use a counter<br />line=1<br />Do Until oFS.AtEndOfStream<br />sText = oFS.ReadLine<br />if line = 1 then line1 = stext<br />line = line + 1<br />Loop<br />lastline=stextAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-55261048337596231132013-03-18T11:53:27.748-07:002013-03-18T11:53:27.748-07:00The 3rd example was very helpful. I did not reali...The 3rd example was very helpful. I did not realize until is started looking at the input closely that it was breaking lines before the end because of the spaces in between fields. This was very useful. ThanksHenry Fraziernoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-63893883300307346662013-02-07T11:35:05.309-08:002013-02-07T11:35:05.309-08:00I don't know if this will help you anymore, bu...I don't know if this will help you anymore, but using the last example, do something like<br /><br />Dim iCursor As Integer<br />Dim sID, sStar, sShow, sLastField<br /><br />iCursor = InStr(1, sLine, ";")<br />sID = Left(sLine, iCursor - 1)<br />iCursor = InStr(iCursor, sLine, ";")<br />sStar = Mid(sLine, Len(sID), iCursor - Len(sID) - 1<br /><br />And just move forward in that fashion.<br /><br />Happy reading!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-40619873124100515482012-09-07T15:04:56.876-07:002012-09-07T15:04:56.876-07:00How to do if I have several fields in each line (s...How to do if I have several fields in each line (some of the fields having spaces in them), separated by comma or any other delimiter?<br /><br />For example<br /><br />(example of a text file i want to read)<br /><br />0017;Peter Griffin;Family Guy;68779<br />0018;Ozzy Osbourne;Still fighting rock singer;89455<br />0023:Stephen King;Horror novel writer;09863<br />0026;Alexandros Patrakis;Greek friend of mine;83766<br />0039;Comfortably Numb;Best rock song ever;90743<br /><br />Thanks for the help and the article. It is superb!<br />Jose Angelhttps://www.blogger.com/profile/04112128111997356269noreply@blogger.comtag:blogger.com,1999:blog-28492262.post-82258087675789128372012-08-26T07:19:44.445-07:002012-08-26T07:19:44.445-07:00In the last sample of reading file, instead of rea...In the last sample of reading file, instead of reading text line by line in<br /><br /><br /> Do Until oFS.AtEndOfStream<br /> sText = oFS.ReadLine<br /> Loop<br /><br /><br /><br />We can write sText = oFS.ReadAll(). Thought I would share it.<br /><br />Thanks,<br />Office Coder<br />www.officecoders.comAnonymoushttps://www.blogger.com/profile/07403937773491216266noreply@blogger.comtag:blogger.com,1999:blog-28492262.post-53414187982542839042011-08-03T23:10:30.562-07:002011-08-03T23:10:30.562-07:00Found the solution for opening files with spaces i...Found the solution for opening files with spaces in filename. use FileSystemObject to read fileAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-64530079765399632302011-08-03T22:39:27.797-07:002011-08-03T22:39:27.797-07:00Do you have any hints how to read a file with spac...Do you have any hints how to read a file with spaces in the name?Erik van Noortnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-451026337627997852011-05-28T04:52:30.004-07:002011-05-28T04:52:30.004-07:00thanx 4 this example t made 2 understand what i di...thanx 4 this example t made 2 understand what i did no understandAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-69871685356689495022010-06-16T07:13:43.787-07:002010-06-16T07:13:43.787-07:00Don't forget 'Line Input' - useful for...Don't forget 'Line Input' - useful for lines with commas (,) whereas an Input statement would start the next line from directly after the comma :)Mark Jhttps://www.blogger.com/profile/06462543962530626366noreply@blogger.comtag:blogger.com,1999:blog-28492262.post-69599244653139656892010-03-01T14:49:59.311-08:002010-03-01T14:49:59.311-08:00Guys, please help!
How can I open a txt file, star...Guys, please help!<br />How can I open a txt file, start reading, say, from line 10, position 4 until the end of the line, then write that into spreadsheet row 3, column 5, and so on - moving down through the lines of the text file, reading values starting from a specific position and writing those values into a spreadsheet? <br />I would really appreciate your help! Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-57882453292206452342010-02-18T20:02:39.177-08:002010-02-18T20:02:39.177-08:00Thanks, alotThanks, alotAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-28165069392772814062009-10-22T07:49:52.303-07:002009-10-22T07:49:52.303-07:00Very helpfulVery helpfulAnonymoushttps://www.blogger.com/profile/13608020184707603871noreply@blogger.comtag:blogger.com,1999:blog-28492262.post-14067939402738757062009-10-19T12:31:32.083-07:002009-10-19T12:31:32.083-07:00Great approach. How about id i want to read the fi...Great approach. How about id i want to read the first line and the last line. Any ideas?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-4355569254105568892009-04-16T13:04:00.000-07:002009-04-16T13:04:00.000-07:00You are the best one. The last scrip me it has bee...You are the best one. The last scrip me it has been most useful. The DLL that that you use is fantastic. You are my salvationAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-67791985005889641222009-01-06T17:07:00.000-08:002009-01-06T17:07:00.000-08:00Thanks mate. Much appreciated. Especially the diff...Thanks mate. Much appreciated. Especially the different approachesAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-28492262.post-17246708209783779052008-12-07T23:13:00.000-08:002008-12-07T23:13:00.000-08:00thank you for your examples. it helps me today :)...thank you for your examples. it helps me today :)Anonymousnoreply@blogger.com