Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

772 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

10 Experts available now in Live!

Get 1:1 Help Now