Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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