PDA

View Full Version : Adding Hyperlinks to images programmatically



RobSteward
04-04-2014, 02:47 AM
Hi guys,

I'm trying to add hyperlinks in my doc. I have two issues here:

1. How to add hyperlinks without starting in a new line (see below):

oDoc.Paragraphs.Add
Set oPara = oDoc.Paragraphs(oDoc.Paragraphs.Count).Range
Set oSelection = oPara.Select
oSelection.TypeText ("E-Mail: " & strEMail & vbCrLf)
oSelection.TypeText ("Internet: ")
oRange = oDoc.Paragraphs(oDoc.Paragraphs.Range.Count).Range
Set oLink = oDoc.Hyperlinks.Add (oRange, "wwwDOTgoogleDOTcom", , , "wwwDOTgoogleDOTcom")

2. How do I add hyperlinks to images (see below):

oDoc.Paragraphs.Add
Set oPara = oDoc.Paragraphs(oDoc.Paragraphs.Count).Range
Set oSelection = oPara.Select
oSelection.InlineShapes.AddPicture ("filepath/file.gif")

I tried figuring out the msdn pages on selection objects, find method, replace text method etc..I just dont get it.
Does anyone have a good tut side or some example code on the methods and properties of hyperlinks as well as the paragraph object ...like basically a good side on learing to code to word? (I did ofc use the search function before posting)

Cheers

RS

macropod
04-04-2014, 05:48 AM
For your first question, your code explicitly adds two new paragraphs, via 'oDoc.Paragraphs.Add' and 'oSelection.TypeText ("E-Mail: " & strEMail & vbCrLf)', where vbCrLf = new paragraph. You choose which one you don't want to add and adjust the code accordingly.

For your second question, it's not apparent whether the picture is supposed to be the hyperlink target or origin.