Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
reading data from text files in VBA
Suppose I want to strore certain settings which are used in an add-in in a text file. Is there a way to access the data in this text file directly using VBA?
Thanks in advance, Arne |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
reading data from text files in VBA
Arne,
Yes, VBA can directly access text files. See on line help for the Open, Input, Line Input, Print, and Close statements. However, it is simpler to save the settings to the registry and use SaveSetting and GetSetting to write and read the registry values. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Arne" wrote in message ... Suppose I want to strore certain settings which are used in an add-in in a text file. Is there a way to access the data in this text file directly using VBA? Thanks in advance, Arne |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
reading data from text files in VBA
An additional reference: http://support.microsoft.com/support...eio/fileio.asp File Access with Visual Basic® for Applications -- Regards, Tom Ogilvy Chip Pearson wrote in message ... Arne, Yes, VBA can directly access text files. See on line help for the Open, Input, Line Input, Print, and Close statements. However, it is simpler to save the settings to the registry and use SaveSetting and GetSetting to write and read the registry values. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Arne" wrote in message ... Suppose I want to strore certain settings which are used in an add-in in a text file. Is there a way to access the data in this text file directly using VBA? Thanks in advance, Arne |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
reading data from text files in VBA
Arne,
Yes, there is, and it's quite simple also! Use the Open statement to open your file, e.g. Open "Path and file name" for Input As #1 Use the Line input statement to get a whole line: Line Input #1, variable reads the line text into variable. Next time you execute you get the next line. Use Input Function to get a specified number of caharacters: variable = Input (x, #1) reads x characters into variable. Next time you execute you get the next x characters (or a different number). If you want to read the whole file line by line, use a Do loop with an end of file condition: Do Until EOF(1) Line Input #1, .... .... Loop Don't forget to close the file when done! Close #1 You can open more files simultaneously, just assign different # numbers, and address by each by its number. Have a look in VBA help for the statements above, it helps. HTH, Nikos "Arne" wrote in message ... Suppose I want to strore certain settings which are used in an add-in in a text file. Is there a way to access the data in this text file directly using VBA? Thanks in advance, Arne |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reading Multiple Files | Excel Worksheet Functions | |||
Reading data arrays from multiple data files in excel | Excel Discussion (Misc queries) | |||
Please Help for a macro reading files not in sequence | Excel Discussion (Misc queries) | |||
Reading dbf files | Excel Discussion (Misc queries) | |||
Reading all files in a folder | Excel Programming |