Results 1 to 2 of 2

Thread: How to open a Word file with ini file info

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Nashville, TN


    What is the string or variable I need to open a word file and make it active by recieving the information from an ini file. I'm still a newbie and my nerves are running short.

    key value=c:\mydoc\mydoc1.doc
    key value=c:\mydocmydoc2.doc

    Thanks, in advance.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    San Jose, CA


    If I understand your question, you have the names of Word doduments in an ini file, and once you retrieve those names from the file you want to automatically run Word. As a newbie you may have trouble following this, but here is an example of one way to do it once you've read the record out of the ini file.
    Option Explicit
    Private Declare Function GetActiveWindow Lib "user32" () As Long
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Sub Form_Load()
    Const text = "key value=c:\mydoc\mydoc1.doc"
    RunFile Right(text, Len(text) - 10), App.Path, vbNormalFocus
    End Sub
    Sub RunFile(ByVal File$, FilePath$, RunStyle)
        Dim sTemp As String
        Dim sMsg As String
        Dim x As Integer
        sTemp = GetActiveWindow()
        x = ShellExecute(sTemp, "Open", File$, "", FilePath$, RunStyle)
        If x < 32 Then
            Select Case x
               Case 0
               sMsg = "The file could not be run due to insufficient system memory or a corrupt program file"
               Case 2
               sMsg = "File Not Found"
               Case 3
               sMsg = "Invalid Path"
               Case 5
               sMsg = "Sharing or protection error"
               Case 6
               sMsg = "Separate data segments are required for each task "
               Case 8
               sMsg = "Insufficient memory to run the program"
               Case 10
               sMsg = "Incorrect Windows version"
               Case 11
               sMsg = "Invalid Program File"
               Case 12
               sMsg = "Program file requires a different operating System "
               Case 13
               sMsg = "Program requires MS-DOS 4.0"
               Case 14
               sMsg = "Unknown program file type"
               Case 15
               sMsg = "Windows program does not support protected memory mode"
               Case 16
               sMsg = "Invalid use of data segments when loading a second instance of a program"
               Case 19
               sMsg = "Attempt to run a compressed program file"
               Case 20
               sMsg = "Invalid dynamic link library"
               Case 21
               sMsg = "Program requires Windows 32-bit extensions"
               Case 31
               sMsg = "No application found for this file"
            End Select
            Err.Raise 12345, "CUtil::RunFile", sMsg
        End If
    End Sub
    Place the two declarations in the Declarations section of a form or module. In my example I have defined a constant named text that has one of your ini lines in it. Remove that const declaration and replace it with code to read the ini file until you get to the line you want. If you have questions, post them or email me.


Posting Permissions

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

Click Here to Expand Forum to Full Width