Help with Word - Hyperlinks.Add

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
Stephen Wells

Help with Word - Hyperlinks.Add

Post by Stephen Wells » 16 Aug 2006, 02:10

 Posted by:  Stephen Wells 

Hi Guys,

I need a bit of help with the function call Hyperlinks.Add from the Word
11 apl. So far I have the code below, but nothing happens. I think it is
to do with the first parameter, I do not know what type of object it is
expecting.

The foHyperlink return parameter has null values for
foHyperlink.GetAddress etc. so i think something is wrong with the
parameters. I have tried fvStringNull in place of the fvOptional.

-------------------------------------------
Call oRange.Collapse( vCollapseStart )
Call fvStringNull.SetString( '' )
Call fvOptional.MakeOptional( )
Call fvTextToDisplay.SetString( 'Hi THere' )
Call fvAddress.SetString( "http://google.com.au" )

Call foHyperlinks.Add( oRange, fvAddress, fvOptional, fvOptional,
fvTextToDisplay, fvOptional, foHyperlink )
-----------------------------------------------

Parameters are:

FunctionalVar: Anchor
Class: Object
FunctionalVar: Address
Class: Variant
FunctionalVar: SubAddress
Class: Variant
FunctionalVar: ScreenTip
Class: Variant
FunctionalVar: TextToDisplay
Class: Variant
FunctionalVar: Target
Class: Variant
FunctionalVar: returnValue
Class: Word_Hyperlink
--------------------------------------------

Windows XP, Word 2003, TD 2005.1

Martin Duty

Re: Help with Word - Hyperlinks.Add

Post by Martin Duty » 16 Aug 2006, 18:02

 Posted by:  Martin Duty 

Stephen,

I don't have Word 11, but on Word 10 Visual Basic Reference, it states the
Anchor parameter as such:
Anchor Required Object. The text or graphic that you want turned into a
hyperlink.

So I would take it that this would be something like a selection of text,
not a range. I would try setting a variant as text and see if that works.

HTH,
Martin

Stephen Wells

Re: Help with Word - Hyperlinks.Add

Post by Stephen Wells » 17 Aug 2006, 02:13

 Posted by:  Stephen Wells 

Hi Martin,

I have tried to use a variant as the parameter but it says 'function
argument 1 does not match declared data type'. Is there an easy way to
set a variable of type 'Object' to some text?

OTOH, i have created a blank Word document and created a macro that does
what i want, with no text currently selected, and it does seem like i
need a range? In this case Selection.Range would be blank as i had a
brand new document with no text? How can i replicate this? (i was trinyg
to do that with the range.collapse part)

ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"http://www.google.com.au/", SubAddress:="", ScreenTip:="", TextToDisplay _
:="link text"

Thanks for your help anyways,

Stephen

Return to “td.sourcecode”

Who is online

Users browsing this forum: No registered users and 0 guests