I have inherited a large file with a format issue I can't solve.
In the attached sample file you will see that the Hyperlink is extended at the start to include a space. I want to trim off the space.
A macro would be helpful.
Sample Hyperlink.zip
I have inherited a large file with a format issue I can't solve.
In the attached sample file you will see that the Hyperlink is extended at the start to include a space. I want to trim off the space.
A macro would be helpful.
Sample Hyperlink.zip
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim lngHL As Long For lngHL = ActiveDocument.Hyperlinks.Count To 1 Step -1 ActiveDocument.Hyperlinks(lngHL).TextToDisplay = Trim(ActiveDocument.Hyperlinks(lngHL).TextToDisplay) Next lbl_Exit: Exit Sub End Sub
Excellent macro
I was going down a cheat route and this is much safer, thank you Greg.
Jon
Hmm I just find trouble sorry about this. Now after the macro I am finding Hyperlinks can get merged. Is there a way to put a space between two "joined" Hyperlinks.
For example:
Sub HlnkFix() Application.ScreenUpdating = False Dim h As Long, Str As String With ActiveDocument For h = .Hyperlinks.Count To 1 Step -1 With .Hyperlinks(h) Str = .TextToDisplay If Left(Str, 1) = " " Then .Range.Characters.First.Previous.InsertAfter " " With .Range.Characters.Last.Next If Right(Str, 1) = " " Then .InsertBefore " " If .Fields.Count > 0 Then .InsertBefore " " End With If Trim(Str) <> Str Then .TextToDisplay = Trim(Str) End With Next End With Application.ScreenUpdating = True End Sub
Last edited by macropod; 03-08-2021 at 03:14 AM.
Cheers
Paul Edstein
[Fmr MS MVP - Word]
So, this trims back the Hyperlink blue and leaves a space. So then I can remove the space after ( with another parse.
But what I needed also was splitting concatenated Hyperlinks made by the previous macro.
Thanks for this macro though.
Something really strange. After running your macro once, I tried it again and got an error. I have encountered this with Word macros on another occasion and the only fix was a reboot. See you in a few mins.
I am getting Run-time error '4198':
Sorry about this I don't know what the difference is...
I added On Error Resume Next and now it does not error.
It would have been better to check the results of Greg's macro before saving your document. See the updated code.
That suggests a faulty Office installation. Try repairing it.
It would probably be more helpful to identify the cause of the error so it can be addressed. Without knowing what line of code you were getting that with and what it was actually processing at the time, it's impossible to know how to address it.
Cheers
Paul Edstein
[Fmr MS MVP - Word]
Thanks for the update.
All was ok I did it on a test document.
Will have to look at repair of Word some other time. It naggs me to upgrade as I am using 2010 version of Word.
Thanks for your help. I can work with these macros to fix these issue. Let call this solved.