Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2017, 08:49 AM
Ulodesk Ulodesk is offline Macro for removing cross-reference fields with specific contents Windows 7 64bit Macro for removing cross-reference fields with specific contents Office 2013
Word 2013 Expert Cert
Macro for removing cross-reference fields with specific contents
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Macro for removing cross-reference fields with specific contents


In proposals at my job, we cross-reference captions in the text callouts. Captions use the label "Figure" and then auto-numbering, both picked up by the cross-references. However, when the cross-reference word "figure" does not begin a sentence, as in

As shown in figure 3, ...

our style is to use the lower-case f. When updating the document (or printing, despite unchecking the relevant links options), the lower case changes back to upper case.
My goal is to be able, when the document is final, to remove the links from the cross-references to the captions, so that I can search/replace for the one's that don't start sentences, replacing the F in Figure with f. (It's unusual to have more than 50 such, and this takes me just a few minutes.)
Since using Ctrl+A and Ctrl+Shift+F9 also removes the caption and any other hyperlinks in what can sometimes be a very lengthy document, this is not a solution. I'd like to have a macro that can remove only the cross-reference fields for captions. Perhaps it could target caption cross-references; perhaps just the word cross-referenced word Figure.
I suspect it could be a fairly simple macro. Help greatly appreciated, as always.
Reply With Quote
  #2  
Old 07-10-2017, 06:27 PM
gmaxey gmaxey is offline Macro for removing cross-reference fields with specific contents Windows 7 32bit Macro for removing cross-reference fields with specific contents Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Add a formatting switch:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/10/2017
Dim oFld As Field
  For Each oFld In ActiveDocument.Fields
    If oFld.Type = 3 Then
      oFld.Select
      If Not InStr(oFld.Code.Text, "\* Lower") > 0 Then
        If MsgBox("Format with lower case?", vbQuestion + vbYesNo, "FORMAT") = vbYes Then
          If InStr(oFld.Code.Text, "\h") > 0 Then
            oFld.Code.Text = Replace(oFld.Code.Text, "\h", "\* Lower \h")
          End If
          oFld.Update
        End If
      Else
        If MsgBox("Format with upper case?", vbQuestion + vbYesNo, "FORMAT") = vbYes Then
          If InStr(oFld.Code.Text, "\h") > 0 Then
            oFld.Code.Text = Replace(oFld.Code.Text, "\* Lower \h", "\h")
          End If
          oFld.Update
        End If
      End If
    End If
  Next
End Sub
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-11-2017, 06:21 AM
Ulodesk Ulodesk is offline Macro for removing cross-reference fields with specific contents Windows 7 64bit Macro for removing cross-reference fields with specific contents Office 2013
Word 2013 Expert Cert
Macro for removing cross-reference fields with specific contents
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default

Hi, Greg, and thank you. I am not a coder, though I have recorded some simple macros and managed occasionally to figure out a few very basic edits. I have tried to understand the macro you provided and have looked at the "deleting fields" section on the page you linked from your site, but I'm afraid I am at a loss. I have no idea where I should be adding a format switch to your macro or what it could possibly be. Would you help me out, please?
Reply With Quote
  #4  
Old 07-11-2017, 12:53 PM
gmaxey gmaxey is offline Macro for removing cross-reference fields with specific contents Windows 7 32bit Macro for removing cross-reference fields with specific contents Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Just run the macro on an active document. It loops through the fields, selects the field if it is a REF field and applies or removes a formatting switch \* Lower based on your actions.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-12-2017, 12:15 PM
Ulodesk Ulodesk is offline Macro for removing cross-reference fields with specific contents Windows 7 64bit Macro for removing cross-reference fields with specific contents Office 2013
Word 2013 Expert Cert
Macro for removing cross-reference fields with specific contents
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Error

Thank you, Greg. I'm getting an error message, though, saying that only comments can appear after End Sub and a few other End commands. Could those last lines be the culprit?

Again, thanks for your help.
Reply With Quote
  #6  
Old 07-13-2017, 08:27 AM
Ulodesk Ulodesk is offline Macro for removing cross-reference fields with specific contents Windows 7 64bit Macro for removing cross-reference fields with specific contents Office 2013
Word 2013 Expert Cert
Macro for removing cross-reference fields with specific contents
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default

Greg, I tried removing the lines after the first End Sub, and the macro seems to work fine now. Thanks again.
Reply With Quote
Reply

Tags
cross-reference, macro, unlink

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for removing cross-reference fields with specific contents Cross Reference REF fields Unlink mktate Word VBA 7 06-24-2016 05:55 AM
Cross reference is bad. Leffken Word 1 06-09-2016 03:12 PM
Macro for removing cross-reference fields with specific contents Totaling specific configuration selections that cross reference multiple fields (tricky) lonniepoet Excel Programming 1 06-09-2016 09:54 AM
Macro for removing cross-reference fields with specific contents 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 01:57 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