Simple bookmark question

D

David JD Bell

(Word 2000) I have a document that prints some labels (3 x 7 per page), all
the labels are the fixed, except that each time they are printed there is a
small code I have to change. To do this I have a bit of text in the header
(not on the labels) that I have Bookmarked, and in each of the 21 labels
there is a REF field to it, so I just edit the text of the bookmark, select
all and hit F9.

I would like to do it in a quick macro. I can pop up a form easily enough,
but don't know the syntax for changing the text in the bookmark

ActiveDocument.Bookmarks("Bookmark Name").Range.Text = tCode

changes it, but also deletes the bookmark. Can anyone point me to the right
way to do this. Ideally the text wouldn't actually be added to the document
and would be just held in a temporary variable.

Thanks

David Bell
 
J

Jezebel

Rather than use a bookmark, why not use a DocVariable or DocProperty? --
then you don't have this problem. Alternatively, use code like this:

Dim pRange as Word.Range

set pRange = ActiveDocument.Bookmarks("Bookmark Name").Range
pRange.Text = tCode
ActiveDocument.Bookmarks.Add "Bookmark Name", pRange
 
C

C Marshall

Jezebel - below is code from a template I have where the bookmarks bkTitle1 and bkTitle2 are getting deleted. I think your code is the solution for me, but I'm confused when I look at my code and try to change or insert your code.

Here is my code:
Private Sub Document_New()

Dim NewsReleaseTitle As String
Dim ForMoreInformationName
Dim ForMoreInformationTelephone
Dim ForMoreInformationEmail

NewsReleaseTitle = TxtTitle1
ForMoreInformationName = cmbxHeader1NameTitle
ForMoreInformationTelephone = cmbxHeader1Telephone
ForMoreInformationEmail = cmbxHeader1Email

' Clears the boxes of any text
With frmNewsRelease



.TxtDate = ""
.TxtTitle1 = ""


End With

frmNewsRelease.Show 'Displays the form

If btnOKClicked = True Then

Bookmarks("bkDate").Range.Text = frmNewsRelease.TxtDate

' these are the bookmarks that are being deleted.
' bkTitle1 is the ' 1st page header.
' bkTitle2 is in the 2nd pg header
Bookmarks("bkTitle1").Range.Text = frmNewsRelease.TxtTitle1
Bookmarks("bkTitle2").Range.Text = frmNewsRelease.TxtTitle1


' move code to here?


Selection.EndKey wdStory
Options.DisplayGridLines = False
With ActiveDocument.ActiveWindow.View
.ShowBookmarks = False
.ShowAll = False
End With
' Moves the insertion point to the end of document and sets
' display to hide table gridlines, bookmarks, and other
' nonprinting characters (sets the display)

Selection.HomeKey Unit:=wdStory

End If

Selection.GoTo What:=wdGoToBookmark, Name:="bkBodyText"
Selection.Find.ClearFormatting


End Sub
 
C

C Marshall

Jezebel - I have a template where the bookmarks bkTitle1 and bkTitle2 are deleted when text is filled in from the User Form.

I think your code could help, but I'm confused as to where to put it.

BkTitle1 is in Header on 1st pg. and BkTitle2 is in header on 2nd pg. of the template.

Below is the code in the "My Document" section of the template code.

Private Sub Document_New()

Dim NewsReleaseTitle As String
Dim ForMoreInformationName
Dim ForMoreInformationTelephone
Dim ForMoreInformationEmail

NewsReleaseTitle = TxtTitle1
ForMoreInformationName = cmbxHeader1NameTitle
ForMoreInformationTelephone = cmbxHeader1Telephone
ForMoreInformationEmail = cmbxHeader1Email

' Clears the boxes of any text
With frmNewsRelease
.TxtDate = ""
.TxtTitle1 = ""
End With

frmNewsRelease.Show 'Displays the form

If btnOKClicked = True Then

Bookmarks("bkDate").Range.Text = frmNewsRelease.TxtDate
'*******These are the bookmarks
Bookmarks("bkTitle1").Range.Text = frmNewsRelease.TxtTitle1
Bookmarks("bkTitle2").Range.Text = frmNewsRelease.TxtTitle1


Selection.EndKey wdStory
Options.DisplayGridLines = False
With ActiveDocument.ActiveWindow.View
.ShowBookmarks = False
.ShowAll = False
End With
' Moves the insertion point to the end of document and sets
' display to hide table gridlines, bookmarks, and other
' nonprinting characters (sets the display)

Selection.HomeKey Unit:=wdStory

End If

Selection.GoTo What:=wdGoToBookmark, Name:="bkBodyText"
Selection.Find.ClearFormatting


End Sub
 
J

Jezebel

DocProperty fields would be a much simpler approach. In the template
headers, in place of your bookmarks, put in fields: { DocProperty Title }.
Then in your code, where you currently try to set the bookmark contents, use

ActiveDocument.BuiltinDocumentProperties("Title") = frmNewsRelease.TxtTitle1
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Fields.Upd
ate
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Updat
e


The first instruction sets the title of the document (equivalent to File >
Properties > Summary). The second and third update the fields in the headers
(equivalent to selecting the header and pressing F9).




C Marshall said:
Jezebel - I have a template where the bookmarks bkTitle1 and bkTitle2 are
deleted when text is filled in from the User Form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top