Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2014, 01:33 PM
arbluecreek arbluecreek is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 32bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 32bit
Novice
Cross Referencing Bookmarks populated from a userform Word 2010
 
Join Date: Jul 2014
Posts: 1
arbluecreek is on a distinguished road
Default Cross Referencing Bookmarks populated from a userform Word 2010

I have very little experience with VBA/Macro's etc.
But I have managed to get a userform up and running that works as expected. Now I have the need to cross reference a few of my bookmark fields throughout the entire document.

I have tried using the cross reference button in Word 2010 and can get it linked to the bookmark ok, but the value doesn't ever update.

I have seen some suggestions for code to use - but I'm not sure where that code would get entered as my first time working with VBA and a Macro was today learning how to get the userform working correctly.





Thanks!
Reply With Quote
  #2  
Old 07-11-2014, 04:32 PM
macropod's Avatar
macropod macropod is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 32bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

When you output text to a collapsed bookmarked range, the text gets inserted after it. The 'correct' way to update a bookmark is to use code like:
Code:
Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
  .Fields.Update
End With
Set BkMkRng = Nothing
End Sub
and call the process with something like:
Call UpdateBookmark("bookmark_name", "bookmark_text")
If needed, you can call the same sub repeatedly, with different bookmark names and/or bookmark text, such as when you have multiple bookmarks to update or when you need to change the contents of a particular bookmark.
The .Fields.Update method updates the cross-references.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 09-17-2014, 08:31 AM
DaniC DaniC is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 64bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 64bit
Novice
 
Join Date: Sep 2014
Posts: 2
DaniC is on a distinguished road
Default similar issue

please help!

i'm having a similar issue. I created a user form to insert text at bookmarks, i have one bookmark id like to repeat throughout the document. I just need to get the cross references to update. ive read : http://www.word.mvps.org/FAQs/Macros...AtBookmark.htm
and now my bookmark isnt deleted but the references dont update. I dont understand how to "call" for the updatebookmark as i'm not familar with coding/coding terms. ive tried inserting the code in multiple places unsuccesfully.

this is what the code looks like now, both the bookmark and text box are "companyname"


Private Sub CommandButton1_Click()
With activedocument
Dim BMRange As Range
Set BMRange = activedocument.Bookmarks("companyname").Range
BMRange.Text = companyname
activedocument.Bookmarks.Add "companyname", BMRange
updatebookmark (companyname)
End With
UserForm1.Hide

End Sub
Reply With Quote
  #4  
Old 09-18-2014, 12:35 AM
macropod's Avatar
macropod macropod is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 64bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It's all pretty basic, really. Assuming companyname is either the name of a textbox on your userform or a string variable's name (you don't say what it is), your code should be:
Code:
Private Sub CommandButton1_Click()
  Call UpdateBookmark("companyname", companyname)
End Sub
Then all you need do is add the UpdateBookmark sub from post #2 to your code module.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 09-18-2014, 04:25 AM
DaniC DaniC is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 64bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 64bit
Novice
 
Join Date: Sep 2014
Posts: 2
DaniC is on a distinguished road
Default

thank you! i actually just used:

.Fields.Update

and that worked perfectly lol just took me forever to find
Reply With Quote
  #6  
Old 05-07-2015, 02:56 PM
AdamE AdamE is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 32bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 32bit
Novice
 
Join Date: May 2015
Posts: 1
AdamE is on a distinguished road
Default Still Need Help

I am an absolute first timer in creating a Userform, but have managed to do it and am now having the same issues that OP had. However, when she said

Quote:
"thank you! i actually just used:

.Fields.Update

and that worked perfectly lol just took me forever to find"
I have absolutely no clue where she was putting the .Fields.Update line.

the only code i have entered is associated with my command button and it is this:

Code:
Private Sub CommandButton1_Click()
With ActiveDocument
  .Bookmarks("Text1").Range _
  .InsertBefore TextBox1
  .Bookmarks("Text2").Range _
  .InsertBefore TextBox2
End With
 
UserForm1.Hide
End Sub
Please help me figure out how to update the bookmark cross-references I have throughout my document.

Thanks!

Adam

Last edited by macropod; 06-05-2015 at 05:23 AM. Reason: Added QUOTE & CODE tags (with code formatting)
Reply With Quote
  #7  
Old 06-05-2015, 05:29 AM
macropod's Avatar
macropod macropod is offline Cross Referencing Bookmarks populated from a userform Word 2010 Windows 7 64bit Cross Referencing Bookmarks populated from a userform Word 2010 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I've been away for 3 1/2 months, hence the delay in replying.

If you used the code I supplied in post #2, you wouldn't have this issue. I assume DaniC's reference to adding '.Fields.Update' is due to the fact it had been omitted from his/her code in post #3.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
bookmark, cross reference, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Bookmarks from a Userform alshcover Word VBA 12 01-12-2015 06:53 PM
Cross-referencing Bookmarks and Formatting kd12 Word 6 06-09-2014 09:20 PM
Cross Referencing Bookmarks populated from a userform Word 2010 issues with cross-referencing khaines Word 7 03-15-2012 03:25 AM
Cross-referencing figure in Word 2003 - Problem ultimateguy Word 0 07-30-2009 12:37 PM
Cross referencing maltesedog Word 0 02-13-2009 07:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft