Solved

cant add hyperlink to word doc

Posted on 2006-07-17
7
296 Views
Last Modified: 2008-02-01
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
Comment
Question by:alexthecodepoet
  • 4
  • 3
7 Comments
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
try


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

Author Comment

by:alexthecodepoet
Comment Utility
Hm, i tried that, but still, nothing happens..
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:alexthecodepoet
Comment Utility
still nothing :(
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
well it works for me. Do you have any error?

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

change there


0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
Comment Utility
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
 

Author Comment

by:alexthecodepoet
Comment Utility
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now