Solved

cant add hyperlink to word doc

Posted on 2006-07-17
7
299 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
ID: 17129287
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
ID: 17131077
Hm, i tried that, but still, nothing happens..
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17131197
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:alexthecodepoet
ID: 17131467
still nothing :(
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17131838
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
ID: 17131850
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
ID: 17132474
Thanks!
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access - Capture pressed key onclick 4 33
passing a value with stream reader AFTER a ";" 3 67
VBA: Select SQL query based on a config Sheet v2 11 44
VB6 ListBox Question 4 44
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

778 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