Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bookmark in the header problem

Status
Not open for further replies.

andrewecu

Programmer
Feb 18, 2002
3
AU

Hi i'm coding with visual basic and i need to insert values in bookmarks in my document template. The document template has bookmarks within its header. If i'm at the body of the text and i try even GoTo a bookmark in the header it gives me an error that it " Word Cannot find the requested bookmark". When it does exist but only in the header.

This is a snippet of my code:
dim wordapp As Word.Application

wordapp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'To go into the page header
wordapp.Selection.GoTo What:=wdGoToBookmark, name:=bookmarkinheader

Is there something i'm missing?? it will give me the error after the execution of that line of code. And its sending me A wall :p

Your help would be appretiated :) Thanks
 
this is how I would do it

Code:
  Dim oApp As Word.Application
  Dim oDoc As Word.Document
  Dim sTemplate As String
  Dim sFile As String
  
  sTemplate = "C:\testtemplate.dot"
  sFile = "C:\test.doc"
  
  Set oApp = New Word.Application
  Set oDoc = oApp.Documents.Add(sTemplate)
  oDoc.Bookmarks("bmkHeader").Range.Text = "this is my header"
  oDoc.Bookmarks("bmkFooter").Range.Text = "this is my footer"
  oDoc.Bookmarks("bmkBody").Range.Text = "this is my body"
  oDoc.SaveAs sFile
  oDoc.Close
  oApp.Quit
  Set oApp = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top