• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

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,
0
alexthecodepoet
Asked:
alexthecodepoet
  • 4
  • 3
1 Solution
 
EDDYKTCommented:
try


objWord.ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
0
 
alexthecodepoetAuthor Commented:
Hm, i tried that, but still, nothing happens..
0
 
EDDYKTCommented:
Try this
                           
objWord.ActiveDocument.Hyperlinks.Add Anchor:=objselection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
alexthecodepoetAuthor Commented:
still nothing :(
0
 
EDDYKTCommented:
well it works for me. Do you have any error?

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

change there


0
 
EDDYKTCommented:
i use this


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
   objWord.ActiveDocument.Hyperlinks.Add Anchor:=objselection.Range, Address:= _
    "http://www.website.com/index.aspx?definitionID=d091283la", _
    SubAddress:="", ScreenTip:= _
    "Screentip Text" _
    , TextToDisplay:="TextToDisplayWord"
   
    objDoc.SaveAs "c:\database\test2_no_hyperlinks4.doc"
0
 
alexthecodepoetAuthor Commented:
Thanks!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now