![]() |
|
|
|
#1
|
|||
|
|||
|
I have got the code working with 4 bookmarks. The 4th bookmark (bmRe) is working except that I want to add the contents of a userform textbox (txtProject). This has been commented out because the code won’t run if left in. The error says that that the variable is not defined. If I add txtProject to the Call code brackets then I get a compile error. Any help would be appreciated. (I am unsure if I should put this on a new thread?).
Code:
Sub UpdateBookmark(bmContact As String, bmCompany As String, bmAddress As String, bmRe As String, StrTxtContact As String, StrTxtCompany As String, StrTxtAddress As String)
Dim BkMkContact As Range
Dim BkMkCompany As Range
Dim BkMkAddress As Range
Dim BkMkRe As Range
With ActiveDocument
'Contact
If .Bookmarks.Exists(bmContact) Then
Set BkMkContact = .Bookmarks(bmContact).Range
BkMkContact.Text = StrTxtContact
.Bookmarks.Add bmContact, BkMkContact
End If
'Company
If .Bookmarks.Exists(bmCompany) Then
Set BkMkCompany = .Bookmarks(bmCompany).Range
BkMkCompany.Text = StrTxtCompany
.Bookmarks.Add bmCompany, BkMkCompany
End If
'Address
If .Bookmarks.Exists(bmAddress) Then
Set BkMkAddress = .Bookmarks(bmAddress).Range
BkMkAddress.Text = StrTxtAddress
.Bookmarks.Add bmAddress, BkMkAddress
End If
'Re
If .Bookmarks.Exists(bmRe) Then
Set BkMkRe = .Bookmarks(bmRe).Range
BkMkRe.Text = "Re: " '& txtProject
.Bookmarks.Add bmRe, BkMkRe
End If
.Fields.Update
End With
Set BkMkContact = Nothing
Set BkMkCompany = Nothing
Set BkMkAddress = Nothing
Set BkMkRe = Nothing
End Sub
Code:
Private Sub CommandButton1_Click()
Call UpdateBookmark("bmContact", "bmCompany", "bmAddress", "bmRe", txtContact, txtCompany, txtAddress)
End Sub
|
|
#2
|
||||
|
||||
|
That's the strangest way I've ever seen anyone try to implement the code in the link I posted. Surely it was clear from that post that the correct way to update each bookmark was by making repeated use of:
Call UpdateBookmark("bookmark_name", "bookmark_text") varying the bookmark name & content for each bookmark???
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to add a bookmark to text within a header | jroger05 | Word VBA | 3 | 07-14-2016 02:28 PM |
| VBA Search Table for Text/Select Text/Insert Hyperlink | sldrellich | Word VBA | 3 | 03-24-2015 01:09 PM |
| Microsoft Word macro to find text, select all text between brackets, and delete | helal1990 | Word VBA | 4 | 02-05-2015 03:52 PM |
| Repeating Bookmark Text | BECKTHOMO | Word | 1 | 03-27-2012 08:34 PM |
Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control
|
skarden | Word | 1 | 12-12-2011 10:39 PM |