Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Multiple Files BadBoy Excel Worksheet Functions 5 January 15th 10 06:26 PM
Reading data arrays from multiple data files in excel Hankjam[_2_] Excel Discussion (Misc queries) 0 February 7th 08 08:29 PM
Please Help for a macro reading files not in sequence Francesco Excel Discussion (Misc queries) 8 April 15th 06 06:13 PM
Reading dbf files Luis Verme Excel Discussion (Misc queries) 6 July 1st 05 01:32 AM
Reading all files in a folder H. Rye Excel Programming 1 January 20th 04 02:15 PM


All times are GMT +1. The time now is 03:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"