View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JLatham JLatham is offline
external usenet poster
 
Posts: 2,203
Default Who do you read an ini file with Excel VBA?

Typically a .ini file is just a simple ASCII text file. The trick to reading
one is to know what you expect to find in it, where to find it and how to
parse it. Here are the basic pieces you'll need. I have one line in it that
simply echos the .ini file contents to the currently active sheet - that can
help while you're trying to code up the parsing. Look at the Instr()
function in VB, it can help with the parsing, and you'll probably end up
using Mid(), Left() and/or Right().

Sub INI_FileReading()
Dim myIniFile As String
Dim iniBuff As Integer
Dim rawLineInput As String

'set up a path to your .ini file
myIniFile = "x:\folder\folder\theFile.ini"
iniBuff = Freefile() ' get available file buffer number
Open myIniFile For Input As #iniBuff

Do While Not (EOF(iniBuff))
Line Input #iniBuff, rawLineInput ' get one line from the file
'next line will show you what's being read from the file
ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = rawLineInput
'parse the lines of data here and save any values you need to use later
Loop
Close #iniBuff

End Sub
"Webtechie" wrote:

Hello,

I need to have a couple of offices use an application. The front end is
written in Excel with Userforms and VBA. The back end is SQL Server.

One office is on site. The other office is in another building. I need to
create a DSN for that office that can see the data across the internet. But
I also need to create an ini file so that the application can retrieve a
value and know whether to access the data directly or use a dsn.

Question
======
What is the code to read an ini from within Excel VBA?


Thanks,

Tony