Solved

how to create a hyperlink on an image in VBA signature script for Outlook.

Posted on 2013-01-10
2
2,026 Views
Last Modified: 2013-01-15
Hi Gurus,

I was wondering if you would be able to help me, I have put together a VBA Script that runs upon client log in and creates a signature in outlook.

The problem I am finding is I cannot seem to find a definitive answer whether it is possible using VBA to hyperlink a banner image we have so that when clicked it goes off to our main site.

I can see you can add a hyperlink for text using objLink = objSelection.Hyperlinks.Add but cannot seem to find anything on doing the same for an image.

Would anyone be able to shed any light on this for me?

On a similar note is there a way to get the text links using objLink = objSelection.Hyperlinks.Add to be formated the same as the rest of the signature text as at the moment it seems to put it in whatever is the default in Word.

I have included our signature code below:

On Error Resume Next 
Set objSysInfo = CreateObject("ADSystemInfo") 
strUser = objSysInfo.UserName 
Set objUser = GetObject("LDAP://" & strUser) 
strName = objUser.FullName 
strTitle = objUser.Title 
strCompany = objUser.company 
strAddress = objUser.streetAddress 
strCounty = objUser.St 
strPhone = objUser.telephoneNumber 
strFax = objUser.faxnumber 
strWebSite = objUser.wWWHomePage
strMail = objUser.mail

Set objWord = CreateObject("Word.Application") 
Set objDoc = objWord.Documents.Add() 
Set objSelection = objWord.Selection 
Set objEmailOptions = objWord.EmailOptions 
Set objSignatureObject = objEmailOptions.EmailSignature 
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries 

objSelection.Style = "No Spacing" 
objSelection.Font.Size = "12" 
objSelection.Font.Name = "Calibri" 
objSelection.Font.Bold = true 
objSelection.TypeText strName &VbLF

objSelection.Font.Size = "12"  
objSelection.Font.Name = "Calibri" 
objSelection.Font.Bold = false 
objSelection.TypeText strTitle &vbLF
objSelection.TypeParagraph() 

objSelection.Style = "No Spacing" 
objSelection.Font.Size = "11"  
objSelection.Font.Name = "Calibri" 
objSelection.Font.Bold = false

objSelection.TypeText "D: " & strPhone &vbLF
objSelection.TypeText "E: " & strMail &vbLF
objSelection.TypeText "F: " & strFax &vbLF
objSelection.TypeText "W: " & strWebSite &vbLF
objShape = objSelection.InlineShapes.AddPicture("\\[FilePath]\logo.png")
objSelection.TypeParagraph()
objSelection.TypeParagraph()

objSelection.TypeText strCompany & " | "
'objSelection.TypeParagraph()
objSelection.TypeText strAddress & vbLF

objSelection.TypeText "Join our rewards scheme "
objLink = objSelection.Hyperlinks.Add(objSelection.Range,"http://www.urladdress.co.uk",,"Address Rewards", "Address")
objSelection.TypeText " |Join the conversation "
objLink = objSelection.Hyperlinks.Add(objSelection.Range,"http://www.urladdress.co.uk/social",,"Be Social", "Be Social")
objSelection.TypeParagraph() 

objShape = objSelection.InlineShapes.AddPicture("\\[filepath]\Banner.jpg")
objSelection.TypeParagraph()
objSelection.Font.Size = "8"  
objSelection.TypeText "Reg. Office: [insert address]"

Set objSelection = objDoc.Range() 
objSignature = objSignatureEntries.Add("AD Signature", objSelection) 
objSignatureObject.NewMessageSignature = "AD Signature" 
objSignatureObject.ReplyMessageSignature = "AD Signature" 
objDoc.Saved = True 
objWord.Quit 

Open in new window

0
Comment
Question by:Flight5497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
terencino earned 500 total points
ID: 38762537
To assist with the first part of your question, adapted from WD2000: Creating Hyperlink Deletes Object Reference, where you currently have your logo...
objShape = objSelection.InlineShapes.AddPicture("\\[FilePath]\logo.png")

Open in new window

...can you change it to ...
sLinkFile="http://www.urladdress.co.uk"
Set objShape = objSelection.InlineShapes.AddPicture("\\[FilePath]\logo.png")
objDoc.Hyperlinks.Add objShape.Range, sLinkFile

Open in new window

...and just do the same for the banner further down.

For the second part of your query, this method adapted from Hyperlink Formatting in Outlook VBScript Signature just repositions the selection at the start of the paragraph that the hyperlink is in, selects it an reformats using normal Word code (note the Constants should go at top of the code, and the person used trial and error to get these:

Const wdParagraph = 4
Const wdExtend = 1
Const wdCollapseEnd = 0
...
...
...
objSelection.TypeText "Join our rewards scheme "
objLink = objSelection.Hyperlinks.Add(objSelection.Range,"http://www.urladdress.co.uk",,"Address Rewards", "Address")
objSelection.TypeText " |Join the conversation "
objLink = objSelection.Hyperlinks.Add(objSelection.Range,"http://www.urladdress.co.uk/social",,"Be Social", "Be Social")
objSelection.StartOf wdParagraph, wdExtend
objSelection.Font.Color = RGB(128,128,128)
objSelection.Font.Size = 10
objSelection.Collapse wdCollapseEnd]
objSelection.TypeParagraph() 

Open in new window


Note I haven't tried this myself, so some experimentation will help get this running.

Hope that helps
...Terry
0
 
LVL 1

Author Comment

by:Flight5497
ID: 38777718
sorry for the delay in my response and awarding of points. Was away on business and forgot to close this up.

This was perfect thank you so much Terry for all your help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question