Solved

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

Posted on 2013-01-10
2
1,905 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now