#1
|
|||
|
|||
Cross Reference to Content Control
Hi all,
I am creating a document in word 2010 with a userform to populate many text content controls (which is working fine). I am trying to create a cross-reference to one of my text content controls and place the information in the footer. I have used assigned a bookmark (including a space before and after the content control) then inserted a cross-reference usung Insert > Cross-reference and navigating to the bookmark. When I do this and update the information with the userform, the reference updates but not the original text content control. I have also used a styleref and that works but when i update the document using the userform, the styleref does not automatically update. Does anyone know what the best way to handle this is? I am not sure why the first one does not work..... it's beyond me but it doesn't. The only other substitute I can think of is have another content control and pass the information in the userform to two places...... Anyway, thanks for any guidance out there. Brent |
#2
|
|||
|
|||
Brent,
I'll say it again. If you are going to use content controls, then why won't you use mapped content controls? http://gregmaxey.com/word_tip_pages/...ols_addin.html |
#3
|
|||
|
|||
Hey Greg,
Fancy seeing you here... haha. I was trying to give you a break on the other forum and poof, here you are. I don't know anything about mapped content controls but I guess I am going to learn. Thanks for the link. B. |
#4
|
||||
|
||||
Hi Brent,
The Content Control/STYLEREF combination works fine for me. Of course, the STYLEREF field must be located in the document header/footer. No vba required. Also, rather than relying on content controls, bookmarks, cross-references and/or STYLEREF fields, I'd suggest you consider populating custom document properties with your userform (which makes it easy to read back the properties into the userform when the document is re-opened) and combine those with DOCPROPERTY fields wherever you want to custom document property values to appear. With this approach, you don't need duplicate custom document properties for each time a value from the userform is to appear - simply add another DOCPROPERTY field to the document pointing to the same custom document property. The attached document (cobbled together for a different query) uses content controls to populate a series of custom document properties, and DOCPROPERTY fields to replicate those values. The principle is the same for use with a userform. PS: Please don't multi-post the same question. I've deleted the separate thread.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Paul,
That of course will work. The reason I am proding Brent toward mapped content controls, is because they are so simple to set up and once done there is no need to have a on exit macro. |
#6
|
|||
|
|||
Thanks fellas,
I am investigating both right now. The one you suggested Paul works. I want to look onto Greg's as well so I can learm about it and make them both work. Thank you again guys. B. |
#7
|
||||
|
||||
Quote:
My reply was originally to a duplicate post by Brent in another thread. At the time, I wasn't aware of your separate reply. I've merged the threads since, which is why you now see my reply here and why we appear to be working at cross purposes.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Brent,
The following (very little error handling) should suffice for most simple mapping requirements. Just add titled CCs in your document and run the code. Copy and paste any titled CC to a new location and it is automatically mapped to the data node (and all other like titled CCs). Code:
Sub MapAColectionOfCustomXMLParts() Dim oCCs As New Collection Dim oCXPart As CustomXMLPart Dim oCC As ContentControl Dim lngIndex As Long Dim strTitle As String 'Create a fresh CustomXMLPart for mapping. On Error Resume Next 'Kill any existing CustomXMLPart used previously. Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace _ ("http//mapCCcollection@namespace.com").Item(1) If Err.Number = 0 Then oCXPart.Delete End If On Error GoTo 0 'Create the new CustomXMLPart. ActiveDocument.CustomXMLParts.Add _ ("<CC_Collection xmlns='http//mapCCCollection@namespace.com'/>") Set oCXPart = ActiveDocument.CustomXMLParts.SelectByNamespace _ ("http//mapCCCollection@namespace.com").Item(1) 'Get unique titles. For Each oCC In ActiveDocument.ContentControls If oCC.Title <> "" Then On Error Resume Next oCCs.Add oCC, oCC.Title End If Next oCC On Error GoTo 0 For lngIndex = 1 To oCCs.Count 'Add a CustomXMLNode for eacj uniqued titled CC. Set oCC = oCCs(lngIndex) strTitle = Replace(oCC.Title, " ", "_") oCXPart.AddNode oCXPart.SelectSingleNode("ns0:CC_Collection"), _ strTitle, , , msoCustomXMLNodeElement Next lngIndex 'Map titled CCs. For Each oCC In ActiveDocument.ContentControls If oCC.Title <> "" Then oCC.XMLMapping.SetMappingByNode oCXPart.SelectSingleNode("//" & Replace(oCC.Title, " ", "_") & "[1]") End If Next oCC lbl_Exit: Exit Sub End Sub |
#9
|
|||
|
|||
Paul,
No worries. Anything that you post is something well posted, cross purposed or not. |
#10
|
|||
|
|||
Thanks for your help fellas
Hey guys,
Thanks for your help. Unfortunately nothing that you have suggested has worked and I don't know why. I have been working at it for hours and something as simple as referencing existing information isn't working. I even have an "updateAllRefFields" that is supposed to update the cross references once the information is updated via userform but nope, that doesn't work either.... Also, I am not the administrator for my computer (work) so the add-in that Greg provided can't be installed on my PC. I truly appreciate all your suggestions and guidance. I am going to try something else and see if that works. Have a good one fellas. Brent |
#11
|
||||
|
||||
Hi Brent,
FWIW, the approach I demonstrated doesn't use REF fields, but DOCPROPERTY fields. So, if your code refers specifically to REF fields, it's not going to update DOCPROPERTY fields (but closing & re-opening the document will).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help with using bookmark and cross-reference | mpdsal | Word | 1 | 07-26-2012 01:05 PM |
Cross-reference problem | Marineboy | Word | 2 | 08-05-2011 03:37 AM |
How to control the caption and their Cross-reference? | Jamal NUMAN | Word | 1 | 04-10-2011 03:23 PM |
2 figures cross reference | mmdmov | Word | 0 | 05-05-2010 09:12 AM |
How do I return from a cross reference? | smoggymark | Word | 0 | 10-21-2008 07:45 PM |