Page 1 of 1 1
Topic Options
#179911 - 2007-08-29 07:16 AM Outlook Signature - Help Converting VB Code
oneill Offline
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.

 Code:
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

 Code:
 
$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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Try this:
 Code:
$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 Offline
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 Offline
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:
 Code:
$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 Offline
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
#179921 - 2007-08-29 10:16 AM Re: Outlook Signature - Help Converting VB Code [Re: oneill]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Who's Howard?

Your problem is the TypeParagraph, which is inserting a <P> into the code when you need a <BR>.

Wherever you are using TypeParagraph, try sending Chr(11) as typed text instead.

Top
#179923 - 2007-08-29 10:27 AM Re: Outlook Signature - Help Converting VB Code [Re: Richard H.]
oneill Offline
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 Offline
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:
 Code:
$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 Offline
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_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Cool, glad Richard could help you out, just got back \:\)
Top
#202324 - 2011-05-24 08:07 PM Re: Outlook Signature - Help Converting VB Code [Re: Arend_]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
Hello everyone, I know the post is very old but I was doing research on creating a maintenance agree in Outlook 2007 and found this post.

And I wonder if it would be possible to change the format of the signature of TEXT to HTML?

If yes, how would it be?


Edited by Valentim (2011-05-24 08:31 PM)
_________________________

Top
#202325 - 2011-05-24 08:30 PM Re: Outlook Signature - Help Converting VB Code [Re: Valentim]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Have you looked at the Signature Tool in the script vault? Uses both HTM and TXT sigs, supports images, and has no reliance on MS Word.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202326 - 2011-05-24 08:31 PM Re: Outlook Signature - Help Converting VB Code [Re: Glenn Barnas]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
I Found another post where I can set font, color, size, but now just need to know how it would be to set an image alongside the text to be something like

|....| Name
|....| Company

where the 2 lines containing "|....|" would a single image
_________________________

Top
#202327 - 2011-05-24 08:37 PM Re: Outlook Signature - Help Converting VB Code [Re: Valentim]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
That's precisely what's demonstrated in that post, along with all the code to create the sigs.. The script vault contains mostly ready-to-use code.

We have a slightly updated version of the same code with an added management tool that we use at many of out clients - no custom coding, just a custom template for the HTM and TXT formats.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202328 - 2011-05-24 09:11 PM Re: Outlook Signature - Help Converting VB Code [Re: Glenn Barnas]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
You are sure to put the text next to a picture as examples?

If yes, I apologize because I did not understand how it would be possible to do...


Attachments
227.jpg
Description:

228.jpg
Description:


_________________________

Top
#202333 - 2011-05-25 01:54 PM Re: Outlook Signature - Help Converting VB Code [Re: Valentim]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
In the Signature Tool as it possible to get him to put the html file in Outlook 2007?

The problem is exactly this, associate your HTML file as the user's signature in Outlook 2007 ... In Outlook Express worked perfectly, but the company used the 2007


Edited by Valentim (2011-05-25 01:55 PM)
_________________________

Top
#204011 - 2012-01-05 02:12 PM Re: Outlook Signature - Help Converting VB Code [Re: Valentim]
meslow Offline
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 :

 Code:
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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org