Wrox Programmer Forums
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2007, 03:19 PM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Hyperlink

Hi everyone,

I know I'm in a Word VBA board but my question is about how to do hyperlink in Word.

I'm currently working in C# to do so but nothing works. The syntax is almost the same so that's why I post here.

Here is my code:

Code:
 oTableDocumentation.Cell(2, 2).Range.Hyperlinks.Add(oWord.Selection.Range, "http://www.google.ca", ref oMissing, ref oMissing, ref oMissing, ref oMissing);
I think my problem is with the Range at the beginning... What am I supposed to put there?

Any help will be really appreciated.

Thanks!

Jaff


 
Old August 27th, 2007, 03:52 PM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think you've misunderstood how the Hyperlinks' Add method should be used.

The first parameter (the Anchor parameter) represents the object that you want associated with a hyperlink. This can be an object (like a graphic) but is more commonly a range of text, as I think is probably the case in your example.

Also, you've accessed the Hyperlinks collection by accessing the Range property of a Table object. This means that you're only accessing those Hyperlinks that exist within the table, and is irrelevant to your needs. It would clearer to access the Hyperlinks collection of the entire document.

So, assuming you want to insert a textual hyperlink into the 2nd cell on row 2 of your table, you might use something like the following:

Code:
object missing = System.Reflection.Missing.Value;
string hyperlinkAddress = "http://www.google.com";

// myTable should be a valid Microsoft.Office.Interop.Word.Table object
object targetRange = myTable.Cell(2, 2).Range;

// wordDoc should be a valid Microsoft.Office.Interop.Word.Document object
wordDoc.Hyperlinks.Add(targetRange, ref hyperlinkAddress, ref missing, ref missing, ref missing, ref missing);
 
Old August 28th, 2007, 08:56 AM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will try this really soon. I'm having trouble with my server right now so I can't test but thanks a lot for the anwser. That's the first time I read something clear like that!

I will give you feedback soon

Thanks

Jaff

 
Old August 28th, 2007, 11:50 AM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot!

It works great! :)

Jaff






Similar Threads
Thread Thread Starter Forum Replies Last Post
hyperlink problem hastikeyvan Classic ASP Professional 5 January 22nd, 2007 07:03 PM
HyperLink Problem monika.vasvani ASP.NET 1.0 and 1.1 Professional 2 September 30th, 2006 05:17 AM
Hyperlink Problem Lalit Pradhan ASP.NET 2.0 Professional 2 June 14th, 2006 09:36 AM
hyperlink problem Abhinav_jain_mca General .NET 3 August 27th, 2004 07:54 AM
hyperlink problem Abhinav_jain_mca SQL Server 2000 1 August 25th, 2004 01:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.