Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual BAsic For Microsoft Word Manipulation - Hyperlink Copy and Paste

Posted on 2004-10-28
2
Medium Priority
?
1,231 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:jmmahon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
RogueSolutions earned 2000 total points
ID: 12439250
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
 

Author Comment

by:jmmahon
ID: 12439479
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question