Link to home
Start Free TrialLog in
Avatar of alexthecodepoet
alexthecodepoet

asked on

cant add hyperlink to word doc

Hello,

I am trying to insert a hyperlink into a word document using this code:

  Dim objWord
   Sub Btn1_onclick()
   call OpenDoc("C:\database\test.doc")
   End Sub



   Sub OpenDoc(strLocation)

   Set objWord = CreateObject("Word.Application")  
   objWord.Visible = True
   

    Set objDoc = objWord.Documents.Open("C:\database\test.doc")
    Set objSelection = objWord.Selection
 
    objWord.Selection.TypeText("This is the text ")
    objWord.Selection.TypeParagraph()
   
    With objSelection.Find
        .Text = "Bensley"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    objSelection.Find.Execute
   ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
   
    objDoc.SaveAs "c:\database\test2_no_hyperlinks4.doc"



I am using a website to do this.

The problem occurs on the ActiveDocument.Hyperlinks.Add line... it wont add a hyperlink.  nothing happens.


Does anyone know how to fix this, or to insert a hyperlink?


Thanks,
Avatar of EDDYKT
EDDYKT
Flag of Canada image

try


objWord.ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
Avatar of alexthecodepoet
alexthecodepoet

ASKER

Hm, i tried that, but still, nothing happens..
Try this
                           
objWord.ActiveDocument.Hyperlinks.Add Anchor:=objselection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
still nothing :(
well it works for me. Do you have any error?

----------                                                                ---
objWord.ActiveDocument.Hyperlinks.Add Anchor:=objselection.Range,

change there


ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!