none
Calling a Bookmark in a Word Template Footer from MS Access RRS feed

  • Question

  • If anyone can help:

    I have created a automated letter writer which creates a letter from a MS Access form based on a Word Template with bookmarks.  I am using code like this:

    WordObj.Selection.GoTo what:=wdGoToBookmark, Name:="Phone"
        WordObj.Selection.TypeText Forms![frmProjectSub-ContractWriter]![csPhone]
       

    to write to the bookmarks, but i have a bookmark in the footer that will not populate the bookmark in the footer because it says that it does not exist.  Can anyone help me?

    Thanks


    • Edited by NoviceVBAuser1775 Thursday, October 6, 2011 11:29 PM
    • Moved by Kee Poppy Monday, October 10, 2011 3:06 AM (From:Visual Basic General)
    Thursday, October 6, 2011 11:28 PM

Answers

  • The wdGotoBookmark constant doesnt work with Headers and Footers, try this method:

    Dim oWord As Word.Application
    
    Set oWord = New Word.Application
    
    oWord.Visible = True
    
    oWord.Documents.Open "C:\YourPathName\YourDocName.docx"
    
    ActiveDocument.Bookmarks("Phone").Range.Text = Forms![frmProjectSub-ContractWriter]![csPhone]
        
    ' saving
    oWord.Documents.Save
    
    ' closing
    oWord.Documents.Close
    
    ' quiting
    oWord.Quit
    
    ' cleaning up
    Set oWord = Nothing
    

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, October 10, 2011 4:38 AM
    Moderator

All replies

  • Probably you have more change on this a little bit complicated (a bookmark) question in the visual studio to office forum

    http://social.msdn.microsoft.com/Forums/en-US/vsto


    Success
    Cor
    Friday, October 7, 2011 7:55 AM
  • Hi NoviceVBAuser,

    Visual Basic for Application forum would fit your question better. I will move this thread there for better support.

    Thanks,


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 10, 2011 3:06 AM
  • The wdGotoBookmark constant doesnt work with Headers and Footers, try this method:

    Dim oWord As Word.Application
    
    Set oWord = New Word.Application
    
    oWord.Visible = True
    
    oWord.Documents.Open "C:\YourPathName\YourDocName.docx"
    
    ActiveDocument.Bookmarks("Phone").Range.Text = Forms![frmProjectSub-ContractWriter]![csPhone]
        
    ' saving
    oWord.Documents.Save
    
    ' closing
    oWord.Documents.Close
    
    ' quiting
    oWord.Quit
    
    ' cleaning up
    Set oWord = Nothing
    

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, October 10, 2011 4:38 AM
    Moderator
  • Thanks, I haven't looked back at this in some time, but I will attempt this and reply back.
    Thursday, December 15, 2011 4:17 PM