Consulting

Results 1 to 2 of 2

Thread: Adding Hyperlinks to images programmatically

  1. #1

    Question Adding Hyperlinks to images programmatically

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •