We help IT Professionals succeed at work.

Word 2016 - More efficient method of searching for hyperlink text

340 Views
Last Modified: 2020-09-17
Hi,

Word 2016/Win10:

I sometimes need to search a Word doc for instances of hyperlink text. I do so as follows in the FIND AND REPLACE Dialog:
1. Click Format.
2. Select Style from the drop-down menu.
Find What Style
In order to locate "Hyperlink", I need to press 'H' over 20 times. Is there a quicker way? Ideally, it would not be a macro since the docs in question are not macro-enabled.

Thanks,
Steve
Comment
Watch Question

Commented:
Steve, try using below steps:
1.Select the hyperlink and press Ctrl+C. This will copy the hyperlink to the Clipboard

2.Press Ctrl+H to display the Replace tab of the Find and Replace dialog box.

3.In the Find What menu, enter the string or word you want to replace.

4.In the Replace With box, enter ^c.

5.Click Replace All.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Hi Sapnaz. Thanks for your response.

I guess I wasn't clear. I'm looking for all hyperlinks within a doc. And, not to replace anything. Just to locate them.

Accordingly in the find/replace dialog box, I live FIND WHAT blank. i.e.
Finding hyperlinks
Once I have chosen the hyperlink style, I keep clicking Find Next, and it locates the hyperlinks one-by-one.

Thanks!

Commented:
There is no such option in word doc. You cannot check all hyperlinks at once. You have to click on 'find next' button to check the next word. You get such option in Notepad++ , where you can check all hyperlinks at once by just selecting it.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
I'm fine with clicking next next next. My issue is that to find the hyperlink option, I must hit the letter 'H' 20+ times. I wish there were a way to jump right to that option. Thanks.
GrahamSkanRetired
CERTIFIED EXPERT
Top Expert 2012

Commented:
You could hit "I" once and then the 'up' key
Stephen KairysTechnical Writer - Consultant

Author

Commented:
You mean in the FIND STYLE dialog? Didn't work for me. Take me to "Emphasis". Thanks.
CERTIFIED EXPERT

Commented:
This is caused by the mysterious "Recommend" tab of the Manage Styles dialog. By default, the Hyperlink style is set to "Hide Until Used" and has high sort order value. As a result, it won't appear in the Styles panel unless it is in use in the document, but also, it won't be located where you'd expect in pick lists like the one you are using in the Find and Replace dialog. (Why the default would not have been show everything in a normal alphabetical order is beyond me.)

Luckily, it isn't a complicated fix.

From the Styles dialog (Shift-Ctrl-Alt-S), click the 3rd button in at the bottom to bring up the Manage Styles dialog. In the Recommend tab, scroll down past the styles beginning with H to select the greyed-our Hyperlink style. Click the "Show" button to set its default visibility to on, then Click "Assign Value..." and choose "1" to set its sort priority to have it included in the top group (i.e. where it should be).

Before you leave the Manage Styles dialog, be sure to click the radio button at the bottom to have the change applied to "New documents based on this template". This typically means the default Normal template will have the changes, but if you are using a custom template, consider doing the same procedure in a default document so your Normal template is fixed too.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Eric,, thank you for your reply! One question:

>>Before you leave the Manage Styles dialog, be sure to click the radio button at the bottom to have the change applied to "New documents based on this template".<<

So, how does the above impact existing documents?
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Also, I just scrolled past the styles beginning with H. But, cannot find the Hyperlink choice. I see that each choice has a line number. Do you recall what line# it is?

Thanks.
CERTIFIED EXPERT

Commented:
1. The template attributes are attached to a document when it is created, so to make the changes apply to new documents, you will need to click that radio button to set it for the template. Applying the changes to the existing document is the default action ("Only in this document").

2. The choices aren't really line numbers; they seem to be used to group sets of styles — and the alphabetic order is within each group. I've never fully understood the rationale for this approach. In any case, when the sort order in the Manage Styles dialog is set to Alphabetical, the Hyperlink style is sorted within the set assigned with the "last" value, so you'll find in near the bottom.

If you assign it a value of 9, it will be displayed above Heading 1 when you choose to show by "Recommended" (Headings have a value of 10). This way, it will be selected when you press the H the first time in the Find Style selector.
Using Word's Manage Style dialog to set visibility and sort order
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Well, this is odd. I followed the steps (setting priority to 1). Hyperlink appeared near the top, although in a sightly different order from your screenshot. But that's OK, I think.

However, after I exited Word, and restarted, it "forgot" my changes.

Did I omit a step?

Thanks.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Hey Eric, did you see the above? Thanks....I think we're very close resolving.
CERTIFIED EXPERT

Commented:
Hmm... The changes I made when I was answering this are still there (after exiting Word and rebooting Windows). Did you click the "New documents based on this template" radio button? I'd set Hyperlink to a value of 9 (as shown in my screen shots) and used the option to make that setting stick to my Normal template. When I opened the document where I'd selected the "Only in this document" setting, the value was still set to 1 (as I'd done in my initial response).

See if the "New documents..." option makes it stick for you. (I'm currently running Word 2016 on Windows 10 (Office 365 subscription version 1707, build 8326.2076), but since this is not a new feature, I would expect it to work on versions since Word 2010.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
So, where did you come up with 9? Wouldn't we want it to be as low as possible to force it to the top? And, I'm pretty sure I clicked "New Documents".

Anyhow, to the best of my memory, when I went back into that RECOMMENDED tab about 10 min. ago, HYPERLINK had moved further up the list in the FIND STYLE dialog. But long story short, even when setting to 9, if I save the doc, exit, and open the same doc, it's not up top.

I have noticed that with the RECOMMENDED tab, that this choice is no longer gray....but it moved way down to its original place (or something close to it.)

I'll get back to this issue Monday, thought it would be a quick fix, but need to edit a doc before i close down for the week.

Thanks,
Steve
CERTIFIED EXPERT

Commented:
I'd used 1 as the value first, but noticed that the Heading styles were 10. Using 9 put Hyperlink "above" Heading 1 (but it was just trial & error; no logic!)

When I open the Manage Styles dialog, Hyperlink is where I noted — but only when I have Sort order=As Recommended. With Sort Order=Alphabetical, it looks all messed up and illogical. Even if you turn on the checkbox for "Show recommended style only" to get rid of all of the normally-hidden ones, the style list does sort alphabetically, but Hyperlink is after Heading 1. I leave it set to use Sort order=As Recommended (and that seems to work best for what you want to see in the Find & Replace Style list).

This feature is pretty esoteric, and seldom covered in even advanced Word courses. It can be useful, but it is one of those "do & forget" tasks when setting up templates: I typically use it once after creating all my custom styles, and then never go back to it again. The ribbon interface gives most people easier access than the Styles dialog — but if you use styles extensively, the ribbon is lacking compared to the greater depth (and access to functionality) you can get with these dialogs.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Yeah with that in mind #9 makes sense. But, it's beyond me why Word's not remembering what I told it. :)

Need to get back to this thing next week, but wondering, does EE allow attaching of screencasts? Maybe if you saw what I'm doing "live", you might notice I'm doing something silly like missing a step... :)

Thanks again and have a good weekend.
CERTIFIED EXPERT

Commented:
I'm not sure about screencasts on EE.

One other possible issue could be related to how your template is being managed. If you are using the default template (i.e. Normal.dotx), it should show in Windows Explorer as having been saved with a time stamp of when you made the changes. Templates are typically saved in C:\Users\*username*\AppData\Roaming\Microsoft\Templates\ — but that can be different on corporate network installations, and they may not permit changes to Word's default template.

If you are on a network that restricts action on the default template, I suggest you try the same steps on a custom template that you can manage yourself. In my case, I manage my network, and all users have local versions of templates, so it isn't an issue I can test.

Update the thread if you find a solution.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Working on a home PC with no network. I'll check NORMAL.DOTX Monday. Thanks.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Thanks. For now, I"m good, as Eric and I have made progress toward a solution.
CERTIFIED EXPERT

Commented:
BTW Stephen, an alternative to get past all of this style order list would be to just set up a VBA macro to do the search for you. You can just record a macro (and optionally assign it to a keyboard shortcut of custom button) — or, if you are familiar with VBA, modify the recorded code to suit. If that would be of interest, I can post some sample code that I have for something similar.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
@Eric, that macro option is tempting...as long as I don't have to deal with .docm (macro-enabled) word docs. I seem to recall that recorded macros do not need docm extensions to work, correct?

Anyhow, I checked NORMAL.DOTX and it's not there.
Where oh where is NormalDotX?NORMAL.DOTM is dated late Friday evening, when I may, repeat may have been working on this issue.

But, check this out. I tried your steps again while I had the file STYLE GUIDE.DOCX open. After I made the changes, the following (to the best of my memory) happened:

1. I tried to exit the file.
2. Word asked me if I wanted to save the changes. (I did not change any content.)
3. I said Yes.
4. Went back into the file --- looked for Hyperlink style - it's near the top.
5. Went into another file - looked for Hyperlink style - it's NOT at the top.
6. Repeated step 4. It's near the top.

And no current change to NORMAL.DOTM.

Sounds like the "style order" - for lack of a better word - is being saved with my individual files? If so, not a great help to me. I do this hyperlink search immediately upon importing a file from  Confluence.

That's it for me for tonight...will check in tomorrow (USA - East Coast). Thanks.
CERTIFIED EXPERT

Commented:
The document was flagged as "changed" when you altered the style order in the Manage Styles dialog. This is normal for Word, and causes the "Save changes?" dialog to be displayed is you exit without specifically saving.

The document you opened in your step #5 would not show the change because it is no longer connected to the template you have now changed. When you make a change that affects a template (as would be the case when you choose the "New documents based on this template" radio button), the template will be saved, but any document that has been created with it is already "disconnected" from it, so you won't see the change when you open it. This is a pretty esoteric issue, and confuses a lot of Word users (I wish Microsoft had made it more clear!). To reattach the changed template, use the "Document Template" button in the Developers ribbon:Use the emplates and Add-ins dialog to re-attach a template
(If you don't see the Developer's ribbon group, add it via the "Customize Ribbon" tab of Word Options: On the right side, turn on the normally-off checkbox for the "Developer" ribbon. (My screen shot includes some of my custom buttons, so it won't look exactly as shown.)

It looks to me as if you are already using Normal.dotm as your default template, so you wouldn't change how it operated if you include a new macro to do this. I'll take a look in my utilities template later on today to see if I can find something similar and post the code if you'd like.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Wow, lots of info here. I'll need time to digest it between the documentation projects I'm trying to finish. Let me get back to you. Thanks.
CERTIFIED EXPERT

Commented:
Here's a modified version of a recorded macro:
Sub JumpToHyperlink()
'
' Jump to next Hyperlink style. Eric Fletcher 2017-08-30
'
' Clear any existing formatting and set up to find the Hyperlink style
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
    With Selection.Find
        .Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        ' other recorded Find settings can be safely deleted (MatchCase, Whole words, etc.)
    End With
' Perform the Find
    Selection.Find.Execute
End Sub

Open in new window


I've added comments to explain some of the code, and noted where I deleted the recorded lines. You can copy & paste this into your VBA panel to save the code, then customize a ribbon group to add a button, or assign it to a keyboard sequence. When you run it, the code will find (and select) the next content in your document that has the Hyperlink style attached to it. If not found, it will display the normal Find message offering to search from the beginning of your document.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Hi Eric, apologies for the delayed reply.

Will the above work in a non-macro-enabled Word doc?

Thanks.
CERTIFIED EXPERT

Commented:
It is a macro, but they reside in the template rather than within the document. I keep my "utility" macros in a separate template (called "Utility.dotm"), and just add it when I need to run them (Developer ribbon; Templates group, Document template). When you remove it, any macro code within it is no longer available.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Ok,Thanks. I'll give it a try when I can.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
OK, Macro is saved. But, please refresh my memory...how do I assign to key sequence (e.g. CTRL-ALT-H or whatever.)
JumpToHyperlinkMacroCodeThank you.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Update:
When i save the .DOCX file currently on screen, I see the following:
Save error (v3)

I'm assuming I did something wrong when installing the macro b/c you indicated I could use the Macro with regular DOCX files. Any ideas?

Thanks again.
CERTIFIED EXPERT

Commented:
DOCM files doesn't include the macros in the file. Instead, it just saves a link to them in the original template. When you are using it in a non-networked environment, this may not be a problem — but if you move it, the link may change to make the macros unavailable.

I think you said you are on a home network. If so, consider putting the macro(s) into the Normal template (the default) to make them available to any document. (I never save a document as DOCM, and all of my DOCX documents have access to any macro code in my Normal template — or to any macro in an added template.)

To set a keyboard sequence to run a macro, use Word options > Customize Ribbon, then "Choose commands from" = Macros. Select the one you want and click in the "Keyboard shortcuts" box below the list. It will let you add your shortcut (letting you know if your sequence is already taken), and propose to save it to the template.

Macros can be very handy — whether just recorded; recorded & modified in VBA; or created from scratch with the VBA editor. There are lots of online resources for VBA code, including within Experts-Exchange (where you can find some superb examples of code as well as many helpful experts!)
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Eric.
1. I'm on a home machine (not network), but I suppose using the normal template applies just fine.

2. How do I insert the macro into the normal template (and where can I find NORMAL.DOT)?

3. I accidentally ran the macro directly from the VB Code window and it found a hyperlink. (Nice!)  Later, I performed an unrelated search and the style was still set to Hyperlink. Is that behavior expected?

Thanks!
CERTIFIED EXPERT

Commented:
Templates are typically stored in "C:\Users\*username*\AppData\Roaming\Microsoft\Templates\", but you can copy the path from the Word Options > Save dialog's "Default personal templates locations".

To insert my macro code, copy it, then open the VBA editor (Alt-F11 or use the Visual Basic button in the Developer ribbon's Code group). If you don't see "New Macros" as a Module on the left, click the Modules folder to expand it and select "New Macros". Then click within the empty main Code panel and paste. The macro code will be inserted, and indented with colours to differentiate between comments and certain VBA structures.

To fix my oversight about leaving the style setting on, copy line 6 and past it before the "End Sub" line. Find and Replace settings are "sticky" so this will clear the formatting set above before the code ends. The screen shot below shows what it looks like in my instance of Visual Basic (yours may differ because some of the panels are optionally open.)
VBA pane showing the JumpToHyperlink code
As you can see, my Normal template has several Modules. Some are temporary for current projects; others are ones I commonly use for projects. (In fact, the "cleanText" module contains code I originally created in WordBasic in the early 1990s, and it still performs some very extensive cleanup tasks in English, French or Spanish documents — and VBA still interprets the WordBasic code!)

I do maintain specific templates for more comprehensive tools, and just add the template when I need the specific function. For example, my "EditTools" template has code to toggle the colour of different languages in the document to make them more visible: the code simply redefines the colour attribute of custom character styles I routinely use to flag foreign languages. All of my templates use such styles (charSpanish, charFrench, etc.) to ensure the correct language dictionaries are used for spell check, grammar and hyphenation — so having these display in different colours during on-screen review is a real boon to an editor. It isn't needed all the time though, so I store the code with other editing tools in a unique template, and just add it when I need it.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
So, should I do the copy-paste of the code at a point where I have no Word documents open? Or should I explicitly open the file in:
C:\Users\*username*\AppData\Roaming\Microsoft\Templates\"

Thanks.
CERTIFIED EXPERT

Commented:
No, the Normal template will be open (unless you have a different one attached) so you can just add the code to it. The template name shows in the VBA panel (upper left), and if you have >1, each will have its own modules. In my screen shot, you can see that Normal is open, but also a blank document (Project 1), and two other documents I happened to have running at the time I took the screen shot.

The changes normally get saved when you close, but to be sure, just click the Save button.

You can edit the Normal template explicitly, but there really is no need to do so. In fact, when you record a macro, it is very convenient to be able to save it directly. If you have >1 template attached, you have the choice of where to put the code — and the "Organizer" button of the Tempaltes and Add-Ins dialog lets you move code (and other parts) from one template to another.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
OK, I did the ALT-F11 thing. However, I can't find the MODULES folder to expand it...
Where's modules folder?Thanks.
PS-Heading into some projects now, so won't be able to respond until later this afternoon or evening. Thanks.
CERTIFIED EXPERT

Commented:
Click the + box beside Normal. You should see sub-folders; one is Modules. It will probably have at least a "NewMacros" module, but I can't confirm because all of our systems here have customized Normal templates. When you double-click it, the Code window should show; if you see something else, use the View menu to select Code (or press F7).
Stephen KairysTechnical Writer - Consultant

Author

Commented:
OK, I opened the New Macros pane. But, there's already a macro there that I must've installed months ago. In fact, I can choose from amongst several. So, I have to figure out how to open a blank pane.....this is progress though. :) Thank you.
CERTIFIED EXPERT

Commented:
No need to open a blank pane; just paste the code after the "End Sub" from whatever is there already. VBA figures it all out by using the "Sub" (or "Public Sub") statement that starts and code segment. You'll get there! ;-)
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Very cool! :)
I installed it, added that second Selection.Find.ClearFormatting statement and manually ran it. And it found a hyperlink. :)

Next step -- to assign a key sequence to it...will come back to that later. But, the above is progress! Thanks for your patient help.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Ok, I'm trying to assign a key sequence, and made it this far:
CustomizingKeyboard
I'd like this command on my home tab. But, when I select HOME TAB on the left, it highlights the BOLD command and displays the existing key sequences. CTRL-B and CTRL-SHIFT-B.

I want to use SHIFT-ALT-H for the Hyper link Macro. However, I'm thinking if I assign it here, it will be used for BOLD. How can I find/add the macro in the Commands list on the right?

Thanks.
CERTIFIED EXPERT

Commented:
Close. You need to scroll down further in the "Categories" set to Macros. Then the right column will list all of the macros available to you. Choose your JumpToHyperlink macro, then press the new shortcut key. Click Assign, and you're good to go.

Here's what it should look like (minus the names of my other macros in the screen shot's list):
Assigning a keyboard shortcut to a macro
This dialog is a bit confusing (as are many related to this topic) because the left column seems to imply that your change will be associated with the ribbons. However, the categories are actually just used to give you easier access to groups of commands and functions. When you clicked the Home Tab category, it narrowed the selection from all commands to show just those commands found somewhere within the Home tab groups.

There's a lot more to it though: this dialog gives you access to some potentially very useful functions that are often otherwise unavailable. If you scroll further down the left panel, you'll see other named categories, but then "Commands not in the Ribbon". When you click it, the right pane list will then include such obscure commands like ApplyHeading1 (to apply the Heading 1 style to the selection; I use the default of Alt-Ctrl-1 all the time); BorderRight (with no default keyboard sequence, but will change the right border of selected paragraphs, table cells, and pictures — in case you need to do that often I suppose); DottedUnderline to do what it says; ExtendSelection (the default is F8, but if you use that for something else, it is handy to be able to reassign it); SentRight (moves the insertion point to the beginning of the next sentence)... Lots of options, and an easy time sink! All Commands will present a very extensive sorted list of all built-in commands available in Word.

Note that when you click on any command, the Description gives you an indication of what it does. If you included a description when you created a recorded macro, you'll see it there too.

The 5 categories below the line under All Commands list the current Macros available to you; the Fonts installed on your system; any Building Blocks you may have defined; all Styles available; and Common Symbols. If a keyboard shortcut you enter has already been assigned, the dialog will advise you and identify the command it is assigned to. You can reassign an existing sequence, but consider it carefully if other users may already be using the default assignment. (This is less of an issue in a home or personal use of Word.)

My only caution in assigning keyboard sequences is to keep it to a number your brain can handle. I prefer to set up custom groups on a ribbon and assign commands to icons or words within it rather than have to remember arcane key sequences. Here's an example of what my Home ribbon currently looks like:
Example of a customized ribbon
As you can see, the area I've circled in red as "1" is named "EFtools", and contains buttons for things I use frequently. The language, style, and paragraph buttons on the left are used in almost every document I work on, and the others give me more convenient access to functions I use fairly frequently — but not enough to clutter my brain with a key sequence:
  • commands like "Mark Entry" and "View Draft" are included on other ribbon groups but mean extra steps to access;
  • commands like Paragraph and the Language pull-down are not on any ribbon group;
  • a macro for Toggle Text Boundaries toggles a checkbox in the lengthy Word Options dialog to let me see where text can flow on a complex page;
  • the "cleanText" green square runs an extensive custom macro I use once in almost every document I work with to automatically clean up content to ensure adherence to specific style guidelines. (It performs many dozens of tasks for English, French and Spanish content; everything from eliminating double spaces & returns, ensuring consistent use of en and em dashes, changing “ and ” quotation marks to  « and » symbols for text flagged as French, to adding an ¿ symbol to the start of any question set with the Spanish language attribute).

The 2nd circled group (named "Layout tweaks") is a set of macros I'm using for a current job to tweak the layout very slightly to improve page- or line-breaks. For example, if I'm trying to tighten copy to fit on a page or to one fewer pages in a chapter, "Cond p1" will condense the character spacing by 0.1 pt for the current selection. This is available via the Font dialog, but inconvenient to go through the steps just to check. If it doesn't tighten it enough, I can click the next button to try 0.2pts. If that doesn't work, I can click the next button to remove any applied condensed spacing and try a different approach (here, reduce the leading to 13.75 pts from the Body Text style's 14pt). These 5 are all quick & dirty recorded macros, and I can delete then and the custom group when I no longer need them for this job.

This is just opening the kimono a bit to how Word's existing UI can be modified to make workflow more efficient. Macros & building blocks can add even more powerful tools — and as you can see from the above, they too can be integrated into the UI.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Well, this is progress. I assigned the macro to a keystroke sequence. And, went through a doc w/hyperlinks.

The good news: Pressing my key sequence stated to iterate through the hyperlinks.
The bad news: It missed the last two, for some reason. And, I did not get the usual Word message that it's reached the end of the document.

FWIW the two that it "missed" were found by the manual method of finding hyperlinks.

What do we try next?
Thanks,
Steve
CERTIFIED EXPERT

Commented:
Hmm... it works properly for me. The ".Wrap = wdFindAsk" line sets the property to ask you if you want to start at the beginning of the document again if it reaches the end without finding the search condition (ref).

Are the missed hyperlinks set with the Hyperlink style? I assume so if your manual find worked, but check to be sure there isn't something different about them. The VBA code should be doing exactly what you'd be doing with the manual method.

Word's F&R dialog reports the number of occurrences, but that isn't available to VBA. However, the quick & dirty code below will report the number of instances found.  

Sub CountHyperlinks()
    Dim iCount As Integer
    iCount = 0
    ' turn off screen updating & jump to start of doc
   ' Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory

    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Hyperlink")

    With Selection.Find
    ' Loop until Word can no longer find the search string
        Do While .Execute
            iCount = iCount + 1
            Selection.MoveRight
        Loop
    End With
    ' Show the number of occurrences found
     msgBox "Found " & iCount & " instances of the Hyperlink style."
     Application.ScreenUpdating = True
End Sub

Open in new window


Copy the above in to your VBA Code window after your other macro code. If you split your screen so both windows are visible, you can press the F8 key to step through the macro line by line to see the effect of each line of active code. I have dual monitors, so I normally can see both at once in full size, but here's a screen grab to show you how it can appear:
Word split screen shown stepping through VBA macro code using the F8 key
The code jumps to the top of the document, then repeats the Find and incrementing the counter until it can't find any more instances. The "Locals" window in the bottom reports the value of local variables (here, iCount is at 3 for the highlighted line). If you don't see Locals, add it via the View menu. Note that I've made line 5 into a comment so you can see how it progresses, but if you remove the leading ' symbol, the code will run without updating the screen after each action (so it is faster).

This should count all instances, and help you identify what may be different with the two that it misses. If I was doing this as a more comprehensive function, I'd set it to return to where it was called (using a bookmark), and add a prompt to allow the user to specify a style name or "Find what" text.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Ok I'll try it Monday or Tuesday.  Thanks.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Thanks, Eric.
Question: Before I dive into the VBA code, is there a way, on-screen to view the "format' of a particular word or sentence? (Per those other hyperlinks that may be different.)
CERTIFIED EXPERT

Commented:
Press Shift-F1 to bring up the Reveal Formatting pane. It shows the formatting of the current selection, and includes options at the bottom to let you toggle style source and formatting mark visibility. In your case, it should show that teh character style Hyperlink is applied for the selection when you've clicked in a hyperlink.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
OK, now I'm feeling pretty silly. :) I forgot the keystroke sequence I assigned to this macro. How can I retrieve it? I went into Options --> Customize Ribbon and got this far (see below), but now I'm stuck....

Customize Ribbon ScreenThanks.
CERTIFIED EXPERT

Commented:
It will show in the Customize Keyboard dialog. Word Options > Customize Ribbon, then click Customize... for Keyboard shortcuts. Scroll down to Macros in the left column (Categories), then choose your macro in the right column. The Current keys will show in panel below.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Thank you.

I tried again, and obtained some more info on the "not found" hyperlinks. Turns out that it's not a case of the text in question not being recognized as a hyperlink. Rather, the previous hyperlink is tripping it up...see these annotated screenshots below.
Annotation per hyperlink behavior
If you wish, I can try to send you a small Word doc containing the problematic links, but might take me little while to produce a scrubbed copy.  Thanks.
CERTIFIED EXPERT

Commented:
Good idea. You can post it on this thread.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
OK. Give me a day or two...Thanks.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Here you go. Thanks.
The second h-link is the one that trips up the macro.
Word-MacroStuckOnHyperlink---Case-2.docx
CERTIFIED EXPERT

Commented:
The Find worked for all 3 instances for me.

However — and this is certainly obscure — the one you can't get past has the ¶ character set with the Hyperlink character style, whereas the other two do not.

I'm not at all sure why it would work for me but not you, but try removing the formatting from the ¶ and see if that makes any difference. You can do it with Find and Replace: in the Find what, use ^p (for paragraph mark) and Style=Hyperlink; in Replace with, use ^& (for Find What Text) and Style=Default Paragraph Font.
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Ah,
So the find/replace you suggested simply removes the hyperlink attribute from the paragraph mark?

Also, here's the macro I had installed. I think I added that line at the end where it turns off the hyperlink attribute but don't think that should make a difference. Do you see any other diffs between yours and mine?


Sub JumpToHyperlink()
'
' Jump to next Hyperlink style. Eric Fletcher 2017-08-30
' Installed by Stphen Kairys 2017-09-07
'
' Clear any existing formatting and set up to find the Hyperlink style
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
    With Selection.Find
        .Text = ""
        .Forward = True
        .Wrap = wdFindAsk
        .Format = True
        ' other recorded Find settings can be safely deleted (MatchCase, Whole words, etc.)
    End With
' Perform the Find
    Selection.Find.Execute
    Selection.Find.ClearFormatting
End Sub
Sub InsertStraightArrow()
'
' InsertStraightArrow Macro
' Insert straight line arrow. Intended for use with textboxes.
'

End Sub

Open in new window


Thanks!
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Stephen KairysTechnical Writer - Consultant

Author

Commented:
Hey Eric,
Haven't forgotten about this question. Projects came up and was sick part of last week...need some time to synthesize the above. Thanks.
CERTIFIED EXPERT

Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Eric Fletcher (https:#a42304351)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

MacroShadow
Experts-Exchange Cleanup Volunteer

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.