Consulting

Results 1 to 20 of 23

Thread: Use Excel To Open Word

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location

    Use Excel To Open Word

    I have several employees and each employee has a table in a access 2000 database with a primary key defined. What I am wanting is to be able to build a form in excel, that has two boxes, one for the Employee name, and the other for the ID. Then a press button, and once this button is pressed it will open the word doc that is in let's say EmployeeName field on the form, and run a mail merge with the ID that is in the IDRequested field on the form.

    I have all of these steps set up manually, ie the access database is built, the word doc with mail merge set up etc. I just would like to try to automate it and make it as simple as enter the employee name, enter the ID requested an Bam, there is what you are looking for.

    I have this code that will open word for me, I just don't know how to pass the two parameters....
    [vba]
    Dim wdApp As Word.Application, wdDoc As Word.Document

    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then 'Word isn't already running
    Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0

    Set wdDoc = wdApp.Documents.Open("C:\temp\anyolddoc.doc")

    wdApp.Visible = True

    End Sub

    [/vba]
    Last edited by Aussiebear; 10-27-2011 at 03:16 PM. Reason: adjusted the code tags for the correct usage

Posting Permissions

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