Robert Chad
asked on
VB Script Help
Hi all
I am trying to write a script to produce signatures for users
i found one here that works well https://www.experts-exchange.com/articles/11911/Standardized-Outlook-signatures-using-Active-Directory-and-Word-Template.html but i want to add the users photo from active directory to the script and can not seem to get it to work
i know the attribute i need to call (thumbnailPhoto) but cant seem to get it to insert into the signature
has anyone done this and can help me here ?
I am trying to write a script to produce signatures for users
i found one here that works well https://www.experts-exchange.com/articles/11911/Standardized-Outlook-signatures-using-Active-Directory-and-Word-Template.html but i want to add the users photo from active directory to the script and can not seem to get it to work
i know the attribute i need to call (thumbnailPhoto) but cant seem to get it to insert into the signature
has anyone done this and can help me here ?
If you want an easy life have a look at crossware. Used in several places and works brilliantly on exchange and Domino servers putting controlled signatures on emails regardless of from phones pc or whatever... Will look back later when on pc free VB script way!
ASKER
Hi Steve thanks but i dont really have the option to do via exchange need to script it at the outlook client
How are you using it at the moment, one-off script to run for a user or every time during login etc? I'm thinking easiest way might be to have photos available either pre-extracted or extracted from AD during login if not already present to a know location, e.g.
\\server\share\photos\user .name.jpg or h:\myphoto.jpg in location on each users network drive or similar, or in their local profile c:\users\user.name\myphoto .jpg
Given that could then have the word template insert picture from known location based on username or fixed path of "%userprofile%\..\myphoto. jpg" or "h:\myphoto.jpg" say?
Otherwise I think would have to extract the photo to a known file location anyway and then insert into the word doc.
Steve
\\server\share\photos\user
Given that could then have the word template insert picture from known location based on username or fixed path of "%userprofile%\..\myphoto.
Otherwise I think would have to extract the photo to a known file location anyway and then insert into the word doc.
Steve
ASKER
Steve i am using This VBS script that fills a word template with AD details modified to suit our environment
i could put the photos in their home directory
i just need to know how i would then load it into the correct location on the word template but haven't been able to work that out
the rest of the script is working fine just need to sort the photo out
'Option Explicit
On Error Resume Next
'========================= ========== ========== =====
'Create Outlook signature from Word template
'========================= ========== ========== =====
'----- Declarations -----
Const wdWord = 2
Const wdParagraph = 4
Const wdExtend = 1
Const wdCollapseEnd = 0
'------------------------- ---------- ---------- ---------- -------
'----- Modify these variables appropriately ----
'------------------------- ---------- ---------- ---------- -------
strTemplatePath = "\\server\Signatures\"
strTemplateName = "ACME_Signature_Template.d ocx"
strReplyTemplateName = "ACME_Reply_Signature_Temp late.docx"
'----- Connect to AD and get user info -----'
Set objSysInfo = CreateObject("ADSystemInfo ")
Set WshShell = CreateObject("WScript.Shel l")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strFirstname = objUser.FirstName
strLastName = objUser.givenName
strInitials = objUser.initials
strName = objUser.FullName
strTitle = objUser.Title
strDescription = objUser.Description
strOffice = objUser.physicalDeliveryOf ficeName
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephone Number
strEmail = objUser.mail
strWeb = objuser.wWWHomePage
'----- Apply any modifications to Active Directory fields -----
'Use company info page if user does not have a Linked-In account specified
if strweb = "" Then strweb = "http://www.linkedin.com/company/58654"
'----- Open Word template in read-only mode {..Open(filename,conversio n,readonly )} -----
Set objWord = CreateObject("Word.Applica tion")
Set objDoc = objWord.Documents.Open(str TemplatePa th & strTemplateName,,True)
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSigna ture
Set objSignatureEntries = objSignatureObject.EmailSi gnatureEnt ries
'----- Replace template text placeholders with user specific info -----
SearchAndRep "[Name]", strName, objWord
SearchAndRep "[Title]", strTitle, objWord
SearchAndRep "[Phone]", strPhone, objWord
SearchAndRep "[Mobile]", strMobile, objWord
SearchAndRep "[Fax]", strFax, objWord
SearchAndRep "[OfficePhone]", strOfficePhone, objWord
SearchAndRep "[email]", strEmail, objWord
SearchAndRep "[web]", strWeb, objWord
'----- Replace template hyperlink placeholders with user specific info -----
SearchAndRepHyperlink "[email]", strWeb, objDoc
SearchAndRepHyperlink "[web]", strWeb, objDoc
'----- Set signature in Outlook -----
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMess ageSignatu re = "Full Signature"
'see note below if a different reply signature is desired
objSignatureObject.ReplyMe ssageSigna ture = "Full Signature"
'----- Close signature template document -----
objDoc.Saved = TRUE
objDoc.Close
objWord.Quit
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -----
'note...if a different reply signature is desired, copy above code from the
'open template section. This time through open
'the reply template instead.
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
'----- Subrouting to search and replace template text placeholders -----
Sub SearchAndRep(searchTerm, replaceTerm, WordApp)
WordApp.Selection.GoTo 1
With WordApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatti ng
.MatchWholeWord = True
.Text = searchTerm
.Execute ,,,,,,,,,replaceTerm
End With
End Sub
'----- Subrouting to search and replace template hyperlink placeholders -----
' Note this can be picky...if it does not work re-create hyperlink in the template
Sub SearchAndRepHyperlink(sear chLink, replaceLink, WordDoc)
Set colHyperlinks = WordDoc.Hyperlinks
For Each objHyperlink in colHyperlinks
If objHyperlink.Address = searchLink Then
objHyperlink.Address = replaceLink
End If
Next
End Sub
i could put the photos in their home directory
i just need to know how i would then load it into the correct location on the word template but haven't been able to work that out
the rest of the script is working fine just need to sort the photo out
'Option Explicit
On Error Resume Next
'=========================
'Create Outlook signature from Word template
'=========================
'----- Declarations -----
Const wdWord = 2
Const wdParagraph = 4
Const wdExtend = 1
Const wdCollapseEnd = 0
'-------------------------
'----- Modify these variables appropriately ----
'-------------------------
strTemplatePath = "\\server\Signatures\"
strTemplateName = "ACME_Signature_Template.d
strReplyTemplateName = "ACME_Reply_Signature_Temp
'----- Connect to AD and get user info -----'
Set objSysInfo = CreateObject("ADSystemInfo
Set WshShell = CreateObject("WScript.Shel
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strFirstname = objUser.FirstName
strLastName = objUser.givenName
strInitials = objUser.initials
strName = objUser.FullName
strTitle = objUser.Title
strDescription = objUser.Description
strOffice = objUser.physicalDeliveryOf
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephone
strEmail = objUser.mail
strWeb = objuser.wWWHomePage
'----- Apply any modifications to Active Directory fields -----
'Use company info page if user does not have a Linked-In account specified
if strweb = "" Then strweb = "http://www.linkedin.com/company/58654"
'----- Open Word template in read-only mode {..Open(filename,conversio
Set objWord = CreateObject("Word.Applica
Set objDoc = objWord.Documents.Open(str
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSigna
Set objSignatureEntries = objSignatureObject.EmailSi
'----- Replace template text placeholders with user specific info -----
SearchAndRep "[Name]", strName, objWord
SearchAndRep "[Title]", strTitle, objWord
SearchAndRep "[Phone]", strPhone, objWord
SearchAndRep "[Mobile]", strMobile, objWord
SearchAndRep "[Fax]", strFax, objWord
SearchAndRep "[OfficePhone]", strOfficePhone, objWord
SearchAndRep "[email]", strEmail, objWord
SearchAndRep "[web]", strWeb, objWord
'----- Replace template hyperlink placeholders with user specific info -----
SearchAndRepHyperlink "[email]", strWeb, objDoc
SearchAndRepHyperlink "[web]", strWeb, objDoc
'----- Set signature in Outlook -----
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Full Signature", objSelection
objSignatureObject.NewMess
'see note below if a different reply signature is desired
objSignatureObject.ReplyMe
'----- Close signature template document -----
objDoc.Saved = TRUE
objDoc.Close
objWord.Quit
'-------------------------
'note...if a different reply signature is desired, copy above code from the
'open template section. This time through open
'the reply template instead.
'-------------------------
'----- Subrouting to search and replace template text placeholders -----
Sub SearchAndRep(searchTerm, replaceTerm, WordApp)
WordApp.Selection.GoTo 1
With WordApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatti
.MatchWholeWord = True
.Text = searchTerm
.Execute ,,,,,,,,,replaceTerm
End With
End Sub
'----- Subrouting to search and replace template hyperlink placeholders -----
' Note this can be picky...if it does not work re-create hyperlink in the template
Sub SearchAndRepHyperlink(sear
Set colHyperlinks = WordDoc.Hyperlinks
For Each objHyperlink in colHyperlinks
If objHyperlink.Address = searchLink Then
objHyperlink.Address = replaceLink
End If
Next
End Sub
OK assuming you have the image file already extracted you should be able to do something like this, I would suggest a cell of a table that has been set to a fixed size - row height, column width and turn off autofit (like script below does)
With WordApp.ActiveDocument.Tab les(1)
.AllowAutoFit = False
.Cell(1, 1).VerticalAlignment = 1 'wdCellAlignVerticalCenter
.Cell(1, 1).Range.ParagraphFormat.A lignment = 1 ' wdAlignParagraphCenter
.Cell(1, 1).Range.InlineShapes.AddP icture FileName:="H:\myphoto.jpg" , LinkToFile:=False, SaveWithDocument:=True
End With
Earlier in the script or as one-off job could pull all the images out into user home drives or into a shared "user photos" directory?
With WordApp.ActiveDocument.Tab
.AllowAutoFit = False
.Cell(1, 1).VerticalAlignment = 1 'wdCellAlignVerticalCenter
.Cell(1, 1).Range.ParagraphFormat.A
.Cell(1, 1).Range.InlineShapes.AddP
End With
Earlier in the script or as one-off job could pull all the images out into user home drives or into a shared "user photos" directory?
ASKER
thanks Steve
i will give this a go on Monday see how it works
should i put this in a specific place in the script ?
i will give this a go on Monday see how it works
should i put this in a specific place in the script ?
ASKER
OK so tried this but it is erroring what am i missing
'----- Find and Insert User Photo -----
With WordApp.ActiveDocument.Tab les(1)
.AllowAutoFit = False
.Cell(1, 1).VerticalAlignment = 1 'wdCellAlignVerticalCenter
.Cell(1, 1).Range.ParagraphFormat.A lignment = 1 ' wdAlignParagraphCenter
.Cell(1, 1).Range.InlineShapes.AddP icture FileName:="C:\Kyle.jpg", LinkToFile:=False, SaveWithDocument:=True
End With
Capture.JPG
'----- Find and Insert User Photo -----
With WordApp.ActiveDocument.Tab
.AllowAutoFit = False
.Cell(1, 1).VerticalAlignment = 1 'wdCellAlignVerticalCenter
.Cell(1, 1).Range.ParagraphFormat.A
.Cell(1, 1).Range.InlineShapes.AddP
End With
Capture.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is assuming there is that one table in the document and top left hand cell of that table to fill in with picture and table sized how you want it - with any other attributes like borders, backgrounds etc. set how wanted already.
If you want to pull out the image from AD on the fly can look at that if this works for the Word bit.
If you want to pull out the image from AD on the fly can look at that if this works for the Word bit.
ASKER
Steve thanks that works now for a static image but if i need to source a different image per user how would i add this ? i can place all the images in a network share if that is easier ?
When on pc later will show, can either see if we can extract the images in the fly from AD for you or if you had ask the photos in a duty based on the username or in the same path for each person, i.e. in their home drive path ( open to users fiddling I suppose ) then in script point at file based on the username.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have it working by putting the photo in their home drive and naming the file the same for all users but it is a manual process to put the photo there for all users was hoping i could point to a directory or AD and grab the photo based on logged in user
We can, just not trivial to work out without PC in front of me from phone :-) When I'm on PC later on will combine code with what you have. There are various example scripts online.
Are you intending this to run every time from a login script or run it once to create their signature?
Are you intending this to run every time from a login script or run it once to create their signature?
e.g. bits from here though that is referring to BMP file, will get you one working from my AD connected systems later.
https://social.technet.microsoft.com/Forums/en-US/1fac22c6-536f-4b4f-a272-79f10642990e/help-stuck-with-vbs-ad-query-that-save-files-from-thumbnailphoto-into-bmp-file-it-doesnt-go-threw?forum=ITCG
https://social.technet.microsoft.com/Forums/en-US/1fac22c6-536f-4b4f-a272-79f10642990e/help-stuck-with-vbs-ad-query-that-save-files-from-thumbnailphoto-into-bmp-file-it-doesnt-go-threw?forum=ITCG
ASKER
yes planning to run at logon via script
Not forgotten... been busy, got appointment in morning (Uk time) will look after that.