+ Reply to Thread
Results 1 to 3 of 3

How to read & write Ini File to Excel

  1. #1
    Registered User
    Join Date
    01-18-2005
    Posts
    62

    How to read & write Ini File to Excel

    Hi,

    I am learning how to read & write ini file to Excel Worksheet. I have a VBA code from a book as belows:

    ReadIniFile
    '**************************************************
    Private Function ReadIniFile() As Integer

    On Error GoTo ReadIniError

    Dim strPath As String
    Dim intFNum As Integer
    Dim strBuf As String
    Dim intRow As Integer
    Dim intCol As Integer

    'Read INI File and write the data to worksheet
    strPath = ActiveWorkbook.Path & "\" & MY_INIFILE
    intFNum = FreeFile()
    Open strPath For Input Access Read Lock Read As #intFNum
    Worksheets("GlobalValues").Unprotect (PASS_SHEET)
    Do While Not EOF(intFNum)
    ------------
    End sub

    I really don't understand the line 'Open strPath For Input Access Read Lock Read As #intFNum'.

    Could any one help me to understand or show me any source (books or web site) which can give me explanation.

    Thanks a lot.

    Nam

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Nam,

    Here is a breakdown of the Open Statement:
    ________________________________________________________________
    Enables input/output (I/O) to a file.

    Syntax

    Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]

    The Open statement syntax has these parts:

    Part Description
    pathname Required. String expression that specifies a file name¾may include directory or folder, and drive.
    mode Required. Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access.
    access Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write.
    lock Optional. Keyword specifying the operations permitted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write.
    filenumber Required. A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number.
    reclength Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered.
    Remarks

    You must open a file before any I/O operation can be performed on it. Open allocates a buffer for I/O to the file and determines the mode of access to use with the buffer.
    If the file specified by pathname doesn't exist, it is created when a file is opened for Append, Binary, Output, or Random modes.
    If the file is already opened by another process and the specified type of access is not allowed, the Open operation fails and an error occurs.

    The Len clause is ignored if mode is Binary.

    Important In Binary, Input, and Random modes, you can open a file using a different file number without first closing the file. In Append and Output modes, you must close a file before opening it with a different file number.
    ________________________________________________________________

    Hope this helps,
    Leith Ross

  3. #3
    Registered User
    Join Date
    01-18-2005
    Posts
    62
    Hello Leith Ross,

    I clearly understand.

    Thank you very much for your support.

    Nam

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1