Visual BAsic For Microsoft Word Manipulation - Hyperlink Copy and Paste

I have approximately 700 word documents that have a hyperlink at the bottom.  It is a pure hyperlink, entered as
{http://intranet.tollbrothersinc.com/tdrive/Intranet Specs/AZ Division/Spec Appliances.doc}.  We would like to use a formatted hyperlink that would show up as
- CLICK HERE TO DISPLAY INTRANET SPECS PORTION OF DOCUMENT -.  I would like to copy the hyperlink address and apply it to the new hyperlink.  I am trying to put everything together to execute on a virtual machine on the startup of all files.  Greatly decreasing the time needed to manually enter everything.  I suupose 2 hours to investigate is better than 10 of sitting and doing Manual.  The current address of the new hyperlink is a file located on my C:\Drive.  I can do almost everything except when I copy the original and try to paste it pastes explicitly.  It isn't actually pasting.  The macro of course says:
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
       "http://intranet.tollbrothersinc.com/tdrive/Intranet Specs/AZ Division/Spec Appliances.doc" _
       , SubAddress:=""

When I really want to use
Address:= Selection.Paste however I am getting compile error expected function or variable pointing at that line.  

The problem is I am using a RECORDED MACRO to actually go into the Hyperlink Window and paste a new address while retaining the formatting, ie the Link Text.  If I could create a new hyperlink that would work also, but I cannot find anything to help me.  I need to be able to copy a string from the document and create a new formatted hyperlink using that address.  Please Help.

The complete Macro is:

Sub Macro4()
'
' Macro4 Macro
' Macro recorded 10/28/04 by MIS Dept.
'
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "http://intranet"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.Cut              ' trying to copy the selected text here
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "- CLICK"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.Range.Hyperlinks(1).Range.Fields(1).Result.Select
    Selection.Range.Hyperlinks(1).Delete
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
       "http://intranet.*********.com/tdrive/appliances.doc"     'want to paste here not declare explicitly
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.HomeKey Unit:=wdLine
    Selection.TypeBackspace
End Sub
jmmahonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RogueSolutionsConnect With a Mentor Commented:
I am a bit confused about what you want to have as the Address parameter.  

If I read your code right then you have hunted out your 'ugly' hyperlink (the "http:// ..." one) and cut it and then you want to paste that as the new address of the pretty hyperlink.

The problem is the Selection.Paste - that's telling word to paste over the current selection whilst in the middle of creating the hyperlink.

I think you'd be better to just grab the ugly hyperlink's text and then apply to the address as a string.  So.

Dim sHyperLink as string

< then everything you have down to the 'cut' command >

sHypeLink = Selection.Text

< then the Selection.cut and everything down to your add >

 ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= sHyperLink

< then the end of your code >

I tested it as best I could and it accepts a string as the address
0
 
jmmahonAuthor Commented:
Thank you.  I've seen this other places and everyone was doing the same.  Using selection.cut and then trying use the string for whatever field as selection.paste.  
0
All Courses

From novice to tech pro — start learning today.