Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Posts
    31

    Unanswered: fill word template from access vba code

    Hi,

    anyone has an idea on how to do this? I'd like to fill a word-template (with bookmarks) from vba-code in MS Access.

    MS Access 97
    MS Word 97

    Grts,
    Kd

  2. #2
    Join Date
    May 2005
    Posts
    119
    I use 2003, but I don't think this code has changed.

    Sub ReportToWord(filename, newfilename)
    On Error GoTo ReportToWord_err

    Dim objWord As Object
    Set objWord = Nothing
    Set objWord = CreateObject("Word.application")
    objWord.Documents.Open filename
    objWord.Visible = False
    With objWord.activedocument.bookmarks
    Item("{bookmark name}").range.Text = "{data to be inserted}"
    End With
    objWord.activedocument.SaveAs newfilename
    objWord.activedocument.Close
    objWord.Quit
    Set objWord = Nothing

    ReportToWord_exit:
    Exit Sub

    ReportToWord_err:
    MsgBox (Err.Description)
    objWord.activedocument.Close
    objWord.Quit
    Set objWord = Nothing
    GoTo ReportToWord_exit


    End Sub

Posting Permissions

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