Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot to read from .ini-file in Excel

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
0
0
SE
I suppose this is really simple, but, how can I read data from an ini-file to a variable in Excel?

The ini-file is situated in C:\USER and is named User.ini. It has a section [Employee] with Name=Sven Svensson

Let’s say I would like to read Name and put it in a variable X.

In Word I use PrivateProfileString but how is it done in Excel?

Mollethedog
 
first you can open the file:
Code:
    fnam = "c:\user\user.ini"
    Open fnam For Input As #1
Then you can read the file, one line at a time. Split the line on the "=" and select on the left side:
Code:
    Do While Not EOF(1)
        lnarr = Split(invar, "=")
        Select Case lnarr(0)
            Case "Name"
                x=linarr(1)
       End Select
    Loop
    Close #1

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top