title: vbs Outlook Signature, different result on 2013 compared to 2010/2016 - Selection.GoTo?
body: <p>I found this script that uses a Word template and placeholders to generate an Outlook signature and set the generated signature in Outlook. - Link removed due to not having more than 10 reputation - </p>
  
  <p>I made a few modifications to suit my needs and it worked great when testing on Outlook 2010 and 2016. However, I have been having issues with getting it to work with Outlook 2013. The placeholders are not being replaced the relevant information.</p>
  
  <pre><code>On Error Resume Next
  
  Const wdWord = 2
  Const wdParagraph = 4
  Const wdExtend = 1
  Const wdCollapseEnd = 0
  
  
  strTemplatePath = "\\server\dir\"
  strTemplateName = "SignatureTemplate.docx"
  strReplyTemplateName = "SignatureTemplateReply.docx"
  
  
  '----- Connect to AD and get user info -----'
  Set objSysInfo = CreateObject("ADSystemInfo")
  Set WshShell = CreateObject("WScript.Shell")
  
  strUser = objSysInfo.UserName
  Set objUser = GetObject("LDAP://" &amp; strUser)
  
  strFirstname = objUser.FirstName
  strLastName = objUser.givenName
  strDepartment = objUser.Department
  strInitials = objUser.initials
  strName = objUser.FullName
  strTitle = objUser.Title
  strDescription = objUser.Description
  strOffice = objUser.physicalDeliveryOfficeName
  strCred = objUser.info
  strStreet = objUser.StreetAddress
  strLocation = objUser.l
  strPostCode = objUser.PostalCode
  strPhone = objUser.TelephoneNumber
  strMobile = objUser.Mobile
  strFax = objUser.FacsimileTelephoneNumber
  strEmail = objUser.mail
  strWeb = ""
  
  'New Signature
  Set objWord = CreateObject("Word.Application")
  Set objDoc = objWord.Documents.Open(strTemplatePath &amp; strTemplateName,,True)
  Set objEmailOptions = objWord.EmailOptions
  Set objSignatureObject = objEmailOptions.EmailSignature
  Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
  
  
  SearchAndRep "[Name]", strName, objWord
  If strTitle = "" Then 
  SearchAndRep "[Title]", (objDoc.Bookmarks("title").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Title]", strTitle, objWord
  End If
  If strDepartment = "" Then 
  SearchAndRep "[Department]", (objDoc.Bookmarks("department").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Department]", strDepartment, objWord
  End If
  SearchAndRep "[Phone]", strPhone, objWord
  If strMobile = "" Then 
  SearchAndRep "[Mobile]", (objDoc.Bookmarks("mobile").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Mobile]", strMobile, objWord
  End If
  SearchAndRep "[Fax]", strFax, objWord
  SearchAndRep "[OfficePhone]", strOfficePhone, objWord
  SearchAndRep "[email]", strEmail, objWord
  SearchAndRep "[web]", strWeb, objWord
  If strOffice = "" Then 
  SearchAndRep "[Office]", (objDoc.Bookmarks("office").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Office]", strOffice, objWord
  End If
  
  
  
  SearchAndRepHyperlink "[email]", strWeb, objDoc
  SearchAndRepHyperlink "[web]", strWeb, objDoc
  
  
  
  Set objSelection = objDoc.Range()
  objSignatureEntries.Add "Full Signature", objSelection
  objSignatureObject.NewMessageSignature = "Full Signature"
  
  'see note below if a different reply signature is desired
  'objSignatureObject.ReplyMessageSignature = "Reply Signature"
  
  
  
  objDoc.Saved = TRUE
  objDoc.Close
  objWord.Quit
  
  '______________________
  
  'Reply Signature
  Set objWord = CreateObject("Word.Application")
  Set objDoc = objWord.Documents.Open(strTemplatePath &amp; strReplyTemplateName,,True)
  Set objEmailOptions = objWord.EmailOptions
  Set objSignatureObject = objEmailOptions.EmailSignature
  Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
  
  SearchAndRep "[Name]", strName, objWord
  If strTitle = "" Then 
  SearchAndRep "[Title]", (objDoc.Bookmarks("title").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Title]", strTitle, objWord
  End If
  If strDepartment = "" Then 
  SearchAndRep "[Department]", (objDoc.Bookmarks("department").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Department]", strDepartment, objWord
  End If
  SearchAndRep "[Phone]", strPhone, objWord
  If strMobile = "" Then 
  SearchAndRep "[Mobile]", (objDoc.Bookmarks("mobile").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Mobile]", strMobile, objWord
  End If
  SearchAndRep "[Fax]", strFax, objWord
  SearchAndRep "[OfficePhone]", strOfficePhone, objWord
  SearchAndRep "[email]", strEmail, objWord
  SearchAndRep "[web]", strWeb, objWord
  If strOffice = "" Then 
  SearchAndRep "[Office]", (objDoc.Bookmarks("office").Range.Paragraphs(1).Range.Delete), objDoc
  Else SearchAndRep "[Office]", strOffice, objWord
  End If
  
  
  SearchAndRepHyperlink "[email]", strWeb, objDoc
  SearchAndRepHyperlink "[web]", strWeb, objDoc
  
  
  
  Set objSelection = objDoc.Range()
  objSignatureEntries.Add "Reply Signature", objSelection
  objSignatureObject.ReplyMessageSignature = "Reply Signature"
  
  objDoc.Saved = TRUE
  objDoc.Close
  objWord.Quit
  
  
  
  
  
  '----- Subrouting to search and replace template text placeholders -----
  Sub SearchAndRep(searchTerm, replaceTerm, WordApp)
      WordApp.Selection.GoTo 1
      With WordApp.Selection.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .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(searchLink, replaceLink, WordDoc)
      Set colHyperlinks = WordDoc.Hyperlinks
      For Each objHyperlink in colHyperlinks
          If objHyperlink.Address = searchLink Then                                
              objHyperlink.Address = replaceLink
              End If
      Next
  End Sub
  
  'WScript.Echo "Signature set"
  </code></pre>
  
  <p>I found this post - <a href="https://social.msdn.microsoft.com/Forums/office/en-US/67184929-d7da-4fba-875b-0e1371f46f2f/vbscript-for-outlook-signature-not-work-with-office-2013?forum=worddev" rel="nofollow noreferrer">https://social.msdn.microsoft.com/Forums/office/en-US/67184929-d7da-4fba-875b-0e1371f46f2f/vbscript-for-outlook-signature-not-work-with-office-2013?forum=worddev</a> where the answer suggested that the Selection.GoTo was not set correctly. I followed his suggestion but this would not resolve the issue.</p>
  
  <p>The rest of the code seems to work on 2013, the Word template is used and copied into Outlook and set as a signature but the placeholders are not replaced with the active directory information. So the signature (for Outlook 2013) ends up being set as:</p>
  
  <p>[Name]</p>
  
  <p>[Title]</p>
  
  <p>[OfficePhone]</p>
  
  <p>[Mobile]</p>
  
  <p>Thanks very much for your time.</p>