Re-applying 'Hyperlink'-character style to all internet and e-mailaddresses

A

andreas

Dear Experts:

I got a long document where internet and e-mail adresses such as ...
www.google.de or
(e-mail address removed)

.... have lost their character style "Hyperlink".

How can I get Word via VBA to re-apply this character style to all
occurrences of URL's and e-mail addresses.

Help is much appreciated.

Thank you very much in advance.

Regards, Andreas
 
J

Jay Freedman

The solution depends on exactly what you mean by "have lost their
character style "Hyperlink". If the text in question still consists of
hyperlinks (that is, when you hover over one it shows the destination,
and clicking or Ctrl+clicking activates the link), then this macro
will reapply the style to make them look right:

Sub RestoreHyperlinkStyle()
Dim hl As Hyperlink
For Each hl In ActiveDocument.Hyperlinks
hl.Range.Style = wdStyleHyperlink
Next
End Sub

However, if they are now just plain text and not hyperlinks (maybe
because the hyperlink fields have been unlinked by Ctrl+Shift+F9),
then a macro isn't required--all you need to do is run AutoFormat. If
you have Word 2003 or earlier, follow these steps:

1. Click Tools > AutoCorrect Options > AutoFormat (not "AutoFormat As
You Type").

2. Uncheck all the options except "Internet and network paths with
hyperlinks". Click OK.

3. Click Format > AutoFormat. Make sure "AutoFormat now" is selected
and click OK.

If you have Word 2007 or 2010, follow these similar steps:

1. Right-click a blank area of the Quick Access Toolbar and choose
Customize the Quick Access Toolbar. Select the All Commands category,
select the AutoFormat Now command, and add it to the Quick Access
Toolbar.

2. Click Office button ("File" in 2010) > Word Options > Proofing >
AutoCorrect Options > AutoFormat.

3. Uncheck all the options except "Internet and network paths with
hyperlinks". Click OK.

4. Click the AutoFormat Now button on the Quick Access Toolbar.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

andreas

The solution depends on exactly what you mean by "have lost their
character style "Hyperlink". If the text in question still consists of
hyperlinks (that is, when you hover over one it shows the destination,
and clicking or Ctrl+clicking activates the link), then this macro
will reapply the style to make them look right:

Sub RestoreHyperlinkStyle()
    Dim hl As Hyperlink
    For Each hl In ActiveDocument.Hyperlinks
        hl.Range.Style = wdStyleHyperlink
    Next
End Sub

However, if they are now just plain text and not hyperlinks (maybe
because the hyperlink fields have been unlinked by Ctrl+Shift+F9),
then a macro isn't required--all you need to do is run AutoFormat. If
you have Word 2003 or earlier, follow these steps:

1. Click Tools > AutoCorrect Options > AutoFormat (not "AutoFormat As
You Type").

2. Uncheck all the options except "Internet and network paths with
hyperlinks". Click OK.

3. Click Format > AutoFormat. Make sure "AutoFormat now" is selected
and click OK.

If you have Word 2007 or 2010, follow these similar steps:

1. Right-click a blank area of the Quick Access Toolbar and choose
Customize the Quick Access Toolbar. Select the All Commands category,
select the AutoFormat Now command, and add it to the Quick Access
Toolbar.

2. Click Office button ("File" in 2010) > Word Options > Proofing >
AutoCorrect Options > AutoFormat.

3. Uncheck all the options except "Internet and network paths with
hyperlinks". Click OK.

4. Click the AutoFormat Now button on the Quick Access Toolbar.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.









- Show quoted text -

Hi Jay,

thank you very much for your swift help and comprehensive answer.
Exactly what I was looking for.

Terrific support. Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top