Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2004
    Location
    Derry, Derry, Ireland, Northern
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access opens an invisibile instance of Word (A2k, Word2k)

    Hi all,

    I used some great code from Helen Feddema (http://www.helenfeddema.com) to automate the opening of a Word document from Access and setting up the data source for the document to an Excel file. Please find a sample below. There is error handling built in to start a Word object if Word is not running. The code works fine when Word is already running, but if Word is not running, the code still works - the only problem is that Word is invisible, I can't work with it, and I can't figure out how to get it to display. Any suggestions?

    *****
    Code snippet:

    Dim path As String
    Dim datasourcefile As String
    Dim datasourcefilepath As String
    Dim wordfile As String
    Dim wordfilepath As String
    path = "Cocuments and SettingsAnyUserMy Documents"
    wordfile = "AnyDoc.doc"
    datasourcefile = "DataSource.xls"
    wordfilepath = path & wordfile
    datasourcefilepath = path & datasourcefile

    'create instance of word
    On Error GoTo ErrorHandler
    Dim pappword
    Set pappword = GetObject(, "Word.Application")

    'open the required document
    pappword.Documents.Open wordfilepath
    'set the mail merge data source
    pappword.ActiveDocument.MailMerge.OpenDataSource Name:=datasourcefilepath, Connection:="EntireSpreadsheet"
    Exit Sub
    ErrorHandler:
    'Word is not running; open Word with CreateObject
    If Err.Number = 429 Then
    Set pappword = CreateObject("Word.Application")
    Resume Next
    Else
    MsgBox "Error No: " & Err.Number & "; Description: "
    Set pappword = Nothing
    Exit Sub
    End If

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Access opens an invisibile instance of Word (A2k, Word2k)

    I believe all you really need is to put
    <font color=blue><font face="Georgia">pappword.visible = True</font face=georgia></font color=blue>
    right before the
    <font color=blue><font face="Georgia">Resume Next</font face=georgia></font color=blue>
    in the error handler routine. If you would like more information about using Automation from Access (or other Office apps), there are several MS Kbase articles shown in our tutorial on Automation.
    Wendell

  3. #3
    Lounger
    Join Date
    Jan 2004
    Location
    Derry, Derry, Ireland, Northern
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access opens an invisibile instance of Word (A2k, Word2k)

    Hi Wendell,

    A deliciously simple solution, thanks!

Posting Permissions

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