#179911 - 2007-08-29 07:16 AM
Outlook Signature - Help Converting VB Code
|
oneill
Fresh Scripter
Registered: 2005-03-24
Posts: 27
Loc: Australia
|
Hi All,
I have this VB code that I am trying to convert into Kix, Creates an signature in outlook.
It works up to a certain point and then bombs out and I can't understand why (mainly becuause my VB Scripting is crap).
This is the line of code, I think, where it is having the problems. $objSignatureEntries.Add "AD Signature", $objSelection
The other minor problem I'm having is once the signature is created all of the text is spaced too far apart. I need to be able to do a "Shift Return" instead of a simple "Return" so I don't have such a large space between each line. Does anyone know how to get around this?
I've included both the VB and KIX code Any help would be much appreciated. thanks.
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FullName
strSN = objUser.sn
strmobile = objUser.mobile
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber
strGivenName = objUser.givenname
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.TypeText "Kind Regards,"
objSelection.TypeParagraph()
objSelection.TypeParagraph()
objSelection.TypeText strGivenName & " " & strSN
objSelection.TypeParagraph()
objSelection.TypeText strTitle
objSelection.TypeParagraph()
objSelection.TypeParagraph()
'objSelection.TypeText strDepartment
'objSelection.TypeParagraph()
objSelection.TypeText strCompany
objSelection.TypeParagraph()
objSelection.TypeText "P: " & strPhone
objSelection.TypeParagraph()
objSelection.TypeText "M: " & strmobile
objSelection.TypeParagraph()
objSelection.TypeText strmail
Set objSelection = objDoc.Range()
[color:#CC0000]objSignatureEntries.Add "AD Signature", objSelection[/color]
objSignatureObject.NewMessageSignature = "AD Signature"
objSignatureObject.ReplyMessageSignature = "AD Signature"
objDoc.Saved = True
objWord.Quit
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.FullName
$strSN = $objUser.sn
$strmobile = $objUser.mobile
$strTitle = $objUser.Title
$strDepartment = $objUser.Department
$strCompany = $objUser.Company
$strPhone = $objUser.telephoneNumber
$strGivenName = $objUser.givenname
$strMail = $objUser.mail
$objWord = CreateObject("Word.Application")
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
$objSelection.TypeText "Kind Regards,"
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
$objSelection.TypeText $strGivenName + " " + $strSN
$objSelection.TypeParagraph()
$objSelection.TypeText $strTitle
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
'$objSelection.TypeText strDepartment
'$objSelection.TypeParagraph()
$objSelection.TypeText $strCompany
$objSelection.TypeParagraph()
$objSelection.TypeText "P: " + $strPhone
$objSelection.TypeParagraph()
$objSelection.TypeText "F: 07 3222 9323"
$objSelection.TypeParagraph()
$objSelection.TypeText "M: " + $strmobile
$objSelection.TypeParagraph()
$objSelection.TypeText $strmail
Set $objSelection = $objDoc.Range()
[color:#CC0000]$objSignatureEntries.Add "AD Signature", $objSelection[/color]
$objSignatureObject.NewMessageSignature = "AD Signature"
$objSignatureObject.ReplyMessageSignature = "AD Signature"
$objDoc.Saved = True
$objWord.Quit
|
Top
|
|
|
|
#179914 - 2007-08-29 08:48 AM
Re: Outlook Signature - Help Converting VB Code
[Re: oneill]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Try this:
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.FullName
$strSN = $objUser.sn
$strmobile = $objUser.mobile
$strTitle = $objUser.Title
$strDepartment = $objUser.Department
$strCompany = $objUser.Company
$strPhone = $objUser.telephoneNumber
$strGivenName = $objUser.givenname
$strMail = $objUser.mail
$objWord = CreateObject("Word.Application")
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
$objSelection.TypeText("Kind Regards,")
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
$objSelection.TypeText($strGivenName + " " + $strSN)
$objSelection.TypeParagraph()
$objSelection.TypeText($strTitle)
$objSelection.TypeParagraph()
$objSelection.TypeParagraph()
;objSelection.TypeText($strDepartment)
;objSelection.TypeParagraph()
$objSelection.TypeText($strCompany)
$objSelection.TypeParagraph()
$objSelection.TypeText("P: " + $strPhone)
$objSelection.TypeParagraph()
$objSelection.TypeText("M: " + $strmobile)
$objSelection.TypeParagraph()
$objSelection.TypeText($strmail)
$objSelection = $objDoc.Range()
[color:#CC0000]$objSignatureEntries.Add("AD Signature", $objSelection)[/color]
$objSignatureObject.NewMessageSignature = "AD Signature"
$objSignatureObject.ReplyMessageSignature = "AD Signature"
$objDoc.Saved = 1
$objWord.Quit
If it doesn't work try removing the [color] /[color] tags
|
Top
|
|
|
|
#179916 - 2007-08-29 09:31 AM
Re: Outlook Signature - Help Converting VB Code
[Re: Arend_]
|
oneill
Fresh Scripter
Registered: 2005-03-24
Posts: 27
Loc: Australia
|
Hi Apronk,
Thanks for the prompt reply. I tried your updated version of the code, however, I get the following error: ERROR : IDispatch pointers not allowed in expressions! Line : 78
Line 78 is: $objSignatureEntries.Add("AD Signature", $objSelection)
EDIT: The signature is now being created, it wasn't before.
Any other suggestions?
BTW, the color tags shouldn't be there.
Edited by oneill3 (2007-08-29 09:40 AM)
|
Top
|
|
|
|
#179919 - 2007-08-29 09:49 AM
Re: Outlook Signature - Help Converting VB Code
[Re: oneill]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If line 78 is returning an object, KiXtart will try and display it. As it cannot you will get an error.
If you don't want the object then assign it to a junk variable:
$DISCARD=$objSignatureEntries.Add("AD Signature", $objSelection)
|
Top
|
|
|
|
#179920 - 2007-08-29 10:02 AM
Re: Outlook Signature - Help Converting VB Code
[Re: Richard H.]
|
oneill
Fresh Scripter
Registered: 2005-03-24
Posts: 27
Loc: Australia
|
Hi Howard,
It Worked! thanks a million (as always ).
Any idea on how to stop the extra spaces between the lines? e.g. Microsoft Office
I need to be able to script the Shift+Enter
Edited by oneill3 (2007-08-29 10:06 AM)
|
Top
|
|
|
|
#179923 - 2007-08-29 10:27 AM
Re: Outlook Signature - Help Converting VB Code
[Re: Richard H.]
|
oneill
Fresh Scripter
Registered: 2005-03-24
Posts: 27
Loc: Australia
|
Sorry Richard, I have no idea who howard is, serious case of brain fade.
how would I go about sending a Chr(11)?
|
Top
|
|
|
|
#179924 - 2007-08-29 10:39 AM
Re: Outlook Signature - Help Converting VB Code
[Re: oneill]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Just use TypeText. You can catenate it to your text, or keep it on seperate lines. Something like this:
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.FullName
$strSN = $objUser.sn
$strmobile = $objUser.mobile
$strTitle = $objUser.Title
$strDepartment = $objUser.Department
$strCompany = $objUser.Company
$strPhone = $objUser.telephoneNumber
$strGivenName = $objUser.givenname
$strMail = $objUser.mail
$objWord = CreateObject("Word.Application")
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
$objSelection.TypeText("Kind Regards,")
$objSelection.TypeText(Chr(11))
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strGivenName + " " + $strSN)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strTitle)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText(Chr(11))
;objSelection.TypeText($strDepartment)
;$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strCompany)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText("P: " + $strPhone)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText("M: " + $strmobile)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strmail)
$objSelection = $objDoc.Range()
$objSignature=$objSignatureEntries.Add("AD Signature", $objSelection)
$objSignatureObject.NewMessageSignature = "AD Signature"
$objSignatureObject.ReplyMessageSignature = "AD Signature"
$objDoc.Saved = 1
$objWord.Quit
|
Top
|
|
|
|
#179927 - 2007-08-29 10:46 AM
Re: Outlook Signature - Help Converting VB Code
[Re: Richard H.]
|
oneill
Fresh Scripter
Registered: 2005-03-24
Posts: 27
Loc: Australia
|
It works great, thanks.
|
Top
|
|
|
|
#179934 - 2007-08-29 03:19 PM
Re: Outlook Signature - Help Converting VB Code
[Re: oneill]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Cool, glad Richard could help you out, just got back
|
Top
|
|
|
|
#202328 - 2011-05-24 09:11 PM
Re: Outlook Signature - Help Converting VB Code
[Re: Glenn Barnas]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
|
Top
|
|
|
|
#204011 - 2012-01-05 02:12 PM
Re: Outlook Signature - Help Converting VB Code
[Re: Valentim]
|
meslow
Just in Town
Registered: 2011-12-29
Posts: 2
Loc: France
|
Hi !
I was working on a similar Signature but I need to create a Table and add data in it. I succed in creating my Table but i dont anderstant how to merge 2 cells together.
Here is the original Cells Merge VB usage :
Set myTable = ActiveDocument.Tables(1)
Set myRange = ActiveDocument.Range(myTable.Cell(1, 1) _
.Range.Start, myTable.Cell(1, 2).Range.End)
myRange.Cells.Merge
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 331 anonymous users online.
|
|
|