PDA

View Full Version : Hyperlink from Excel To Word



jrdnoland
10-08-2007, 12:38 PM
Using VBA how would I copy a hyperlink address from an excel worksheet and paste that hyperlink address into a word document?

I can loop through the worksheet and check each cell for a hyperlink and then set the hyperlink address equal to a variable.
But I don't know enough about Word vba to be able to make that address appear in a Word document.

If ActiveCell.Value <> "" Then
If ActiveCell.Hyperlinks.Count > 0 Then
ResultsSummaryText1 = ActiveCell.Hyperlinks(1).Address
End If
End If
Any help would be appreciated.

fumei
10-08-2007, 07:58 PM
Not quite following. Do want the address to end up in Word as another hyperlink, or just as text?

AND, where exactly do you want it in the Word document? A specific location? Anywhere? At the cursor?

Plus, how exactly are you dealing with the instance of Word. Your code looks like you are running the VBA from Excel, so I assume you are making an instance of Word...say objWord, and that you have an active document, say objDoc.
If ActiveCell.Value <> "" Then
If ActiveCell.Hyperlinks.Count > 0 Then
ResultsSummaryText1 = ActiveCell.Hyperlinks(1).Address
objDoc.Hyperlinks.Add Anchor:=Selection.Range, _
Address:= ResultsSummaryText1, _
SubAddress:="", ScreenTip:="", _
TextToDisplay:=ResultsSummaryText1
End If
End If would insert ResultsSummaryText1, as a hyperlink at the current cursor position.

Note: the displayed text would be the full address. If you wanted different displayed text:

eg http//:www.microsoft.com (the link) displayed as "Microsoft", you would do something like:objDoc.Hyperlinks.Add Anchor:=Selection.Range, _
Address:= "http://www.microsoft.com", _
SubAddress:="", ScreenTip:="", _
TextToDisplay:="Microsoft"with, again, the Document object being objDoc.

jrdnoland
10-09-2007, 03:34 AM
Yes, I want the address to end up in word as a hyperlink. And, yes I'm running vba code from Excel.

I've opened up a word document and would like to put the excel hyperlink into the word document at perhaps a bookmark.

So I have an excel workbook open and a word document open. How would I reference the open word document (call it opendoc.doc) and put the excel hyperlink address at a specific bookmark in the document?

I work mostly with excel and I'm not real sure about word vba.

Thanks for the help!

fumei
10-09-2007, 06:51 AM
You need an instance of Word. Look up in Help. Or in the KB here. If you know the document is open in Word, then you could use GetObject. If the document is not open (there is no instance of Word) you could use CreateObject.

Look these up in Help.