Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2016, 08:02 PM
mktate mktate is offline Cross Reference REF fields Unlink Windows 10 Cross Reference REF fields Unlink Office 2010 64bit
Novice
Cross Reference REF fields Unlink
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default Cross Reference REF fields Unlink

I have a long document with conditional numbered paragraphs and am trying to include cross references to the conditional paragraph numbers as part of a userform that updates many documents. With my conditional paragraphs, the paragraph numbers are not "visible" until the fields are updated and unlinked. So, when you enter the cross references in the conditional paragraphs, the cross reference dialog box to choose which sections to reference looks like this:



Article I.
Article II.
2.1
2.2
Article I. (this is conditional)---- (after unlinking it will become Article III.)
1.1 (this is conditional) --- (after unlinking it will become section 3.1)
1.1 (this is conditional) --- (after unlinking it will become section 3.2)
Article III. --- (after unlinking, this will be updated to Article IV.)

However, when I update and unlink, the cross references within the conditional Article I, or the sections 1.1, for example, do not update - they retain the original 1.1 (or Article I.) of the conditional text. I then tried to update all fields other than REF fields within my userform with the following VBA code:

ActiveDocument.Fields.Update

Dim oField as Field

For each oField in ActiveDocument.Fields
If oField.Type <> wdFieldRef Then ActiveDocument.Fields.Unlink

I thought this would unlink everything other than the REF fields - leaving the REF fields in place - and then I could update them again once all of the paragraphs were no longer conditional (since they would be unlinked). However, it still updated ALL fields, including the REF fields of the cross references so I had no fields left in my document (other than the heading/paragraph numbers and page numbers) - all REF fields were now regular text.

Note also that normally the REF fields show up in the bookmarks dialog box. But, since these are conditional, my bookmark dialog shows no bookmarks; however, when I edit a REF field, the bookmark name correctly shows up in the edit REF field dialog.

Can anyone help with this issue? Thanks.
Reply With Quote
  #2  
Old 06-22-2016, 09:23 PM
macropod's Avatar
macropod macropod is offline Cross Reference REF fields Unlink Windows 7 64bit Cross Reference REF fields Unlink 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

Your code unlinks all fields as soon as it finds one that is not a cross-reference. To update & unlink fields other than cross-references, use code like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
  With Fld
    If .Type <> wdFieldRef Then
      .Update
      .Unlink
    End If
  End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-23-2016, 08:37 AM
mktate mktate is offline Cross Reference REF fields Unlink Windows 10 Cross Reference REF fields Unlink Office 2010 64bit
Novice
Cross Reference REF fields Unlink
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default

I used your code and got the same result. I wasn't clear enough in my original post - the REF fields in the Unconditional text behaves properly and does not unlink (remains a field after applying code); however, the REF fields within the Conditional text does NOT behave properly and DOES unlink - with my code AND with your code.

The issue still is I have a conditional section/paragraph that contains REF fields to another conditional section number. When you do the cross reference it refers to 1.1 since the section numbers do not get updated until you unlink the IF fields. However, that section number DOES NOT update but DOES unlink even though we are telling it not to - and after applying the code the text reads section 1.1 (rather than section 3.1). The REF fields in the unconditional section/paragraph remain fields so they can be updated, but the REF fields in the conditional section/paragraph are now plain text.
Reply With Quote
  #4  
Old 06-23-2016, 03:48 PM
mktate mktate is offline Cross Reference REF fields Unlink Windows 10 Cross Reference REF fields Unlink Office 2010 64bit
Novice
Cross Reference REF fields Unlink
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default

To further clarify, there are three cross reference situations with three different results using both my code and macropod's code:

Situation #1: cross reference within conditional text pointing to a heading within conditional text - result is unlinked text that is not the correct heading number.

Situation #2: cross reference within conditional text pointing to a heading NOT within conditional text - result is unlinked text that IS properly the correct heading number (but cannot be updated).

Situation 3#: cross reference NOT in conditional text pointing to a heading NOT within conditional text - result is field is not unlinked - still exists in document and can be updated properly - the desired result.

As you can see, we don't get the desired result when using cross references within IF fields - so maybe the question is whether anyone knows for sure that you can or cannot get cross references to work properly within IF fields (or somehow be able to unlink the IF field WITHOUT unlinking the REF field contained within it).
Reply With Quote
  #5  
Old 06-23-2016, 04:05 PM
macropod's Avatar
macropod macropod is offline Cross Reference REF fields Unlink Windows 7 64bit Cross Reference REF fields Unlink 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

Quote:
Originally Posted by mktate View Post
I wasn't clear enough in my original post - the REF fields in the Unconditional text behaves properly and does not unlink (remains a field after applying code); however, the REF fields within the Conditional text does NOT behave properly and DOES unlink - with my code AND with your code.
That, presumably, is because your conditional text is controlled by IF fields (which you hadn't mentioned), in which case what's happening is that those get unlinked. To prevent that, you could change:
If .Type <> wdFieldRef Then
to:
If (.Type <> wdFieldRef) And (.Type <> wdFieldIf) Then
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 06-23-2016, 04:40 PM
mktate mktate is offline Cross Reference REF fields Unlink Windows 10 Cross Reference REF fields Unlink Office 2010 64bit
Novice
Cross Reference REF fields Unlink
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default

Thanks for the reply. With conditional text and IF fields you Have To unlink the IF field in order for the heading style/numbering to populate and "set" the text; therefore it is not desired that we prevent the IF fields from unlinking - the opposite is true - we have to get the IF fields to update and unlink but not the Ref cross reference. Any other ideas out there?
Reply With Quote
  #7  
Old 06-23-2016, 06:26 PM
macropod's Avatar
macropod macropod is offline Cross Reference REF fields Unlink Windows 7 64bit Cross Reference REF fields Unlink 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

You cannot unlink the IF field and preserve any other fields within it...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 06-24-2016, 05:55 AM
mktate mktate is offline Cross Reference REF fields Unlink Windows 10 Cross Reference REF fields Unlink Office 2010 64bit
Novice
Cross Reference REF fields Unlink
 
Join Date: Dec 2015
Posts: 26
mktate is on a distinguished road
Default

Ok thanks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross reference is bad. Leffken Word 1 06-09-2016 03:12 PM
Cross Reference REF fields Unlink Totaling specific configuration selections that cross reference multiple fields (tricky) lonniepoet Excel Programming 1 06-09-2016 09:54 AM
Cross Reference REF fields Unlink prevent word fields from unlink mktate Word VBA 5 03-13-2016 02:07 PM
Cross Reference REF fields Unlink Reference number and cross reference for equation numbers to match the thesis format wmac Word 1 05-14-2013 08:54 PM
manipulating cross-reference fields _wim_ Word 0 12-10-2010 05:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:20 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