Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-10
2
Medium Priority
?
2,194 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 2000 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 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