hyperlink to word

S

Spencer.Sadkin

I am trying to run the following from excel with the word library
reference.

Option Explicit
Sub CopyHyperlink()
Dim app As Word.Application
Dim doc As Document
Dim url As String
Set app = New Word.Application
Set doc = app.Documents.Add
app.Visible = True
doc.Hyperlinks.Add Anchor:=Selection.Range, Address:="http://
www.google.com", SubAddress:="", _ ScreenTip:="", TextToDisplay:="Link
Title"

End Sub

the issues is on doc.Hyperlinks.Add Anchor:=Selection.Range,
Address:="http://www.google.com", _ SubAddress:="", ScreenTip:="",
TextToDisplay:="Link Title"

however that line of works just fine if used as standalone and
changing doc to activedocument in the word vba editor any ideas?
 
S

Spencer.Sadkin

I am trying to run the following from excel with the word library
reference.

Option Explicit
Sub CopyHyperlink()
    Dim app As Word.Application
    Dim doc As Document
    Dim url As String
    Set app = New Word.Application
    Set doc = app.Documents.Add
    app.Visible = True
    doc.Hyperlinks.Add Anchor:=Selection.Range, Address:="http://www.google.com", SubAddress:="", _ ScreenTip:="", TextToDisplay:="Link
Title"

End Sub

the issues is on doc.Hyperlinks.Add Anchor:=Selection.Range,
Address:="http://www.google.com",  _ SubAddress:="", ScreenTip:="",
TextToDisplay:="Link Title"

however that line of works just fine if used as standalone and
changing doc to activedocument in the word vba editor  any ideas?

this fixed it but i dont know if its the best
doc.Hyperlinks.Add Anchor:=doc.ActiveWindow.Selection.Range,
Address:="http://www.google.com", SubAddress:="", ScreenTip:="",
TextToDisplay:="Link Title"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top