-
Text Alignment
Hello All,
This is my first post here and I'm sure this is a simple process but I'm just not hitting the nail on the head:
I'm new to Word VBA (and VBA in general) and I've been asked to generate an auto-signature for my companys' Outlook users, I've managed to find code on the Net and from trial and error and a LOT of googling, I've managed to throw a decent auto-signature piece of code together that runs during logon, however, there's only one problem I haven't been able to lick, text alignment. Basically, I want to align everything else in the signature to the right. Everything works properly except the alignment, it is based on code I found on Sue Moxer's Outlook site.
I've searched the forums here and nothing really stands out to me so I'm going to post the code here and hopefully someone can help:
The code:
[vba]
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FullName
strTitle = objUser.Description
strCompany = "Company Name"
strAddress = "Company Address"
strCity = "Company City"
strPhone = "Company Phone"
strTollFree = "Company Toll Free Phone"
strFax = "Company Fax"
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.ParagraphFormat.Alignment = wdAlignParagraphRight
objSelection.TypeParagraph()
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = 10
objSelection.Font.Bold = True
objSelection.TypeText strName & chr(11)
objSelection.Font.Bold = False
objSelection.Font.Italic = True
objSelection.TypeText strTitle & chr(11)
objSelection.Font.Italic = False
objSelection.TypeText chr(11)
objSelection.InlineShapes.AddPicture "C:\Public\Clipart\email-sig-mall.jpg",
true, true
objSelection.TypeText & chr(11)
objSelection.Font.Size = 8
objSelection.TypeText strAddress & chr(11)
objSelection.TypeText strCity & chr(11)
objSelection.TypeText strPhone & chr(11)
objSelection.TypeText strTollFree & chr(11)
objSelection.TypeText strFax & chr(11)
Set objSelection = objDoc.Range()
objSignatureEntries.Add "AD Signature", objSelection
objSignatureObject.NewMessageSignature = "AD Signature"
objSignatureObject.ReplyMessageSignature = "AD Signature"
objDoc.Saved = True
objWord.Quit
[/vba]
Last edited by cw75cdn; 08-20-2008 at 03:10 PM.
-
-
Ok,
So I'm trying a different approach after MUCH reading on the 'Net:
a) create a table
b) insert text/image content into table
c) align cell of table to the right
This seems to be working rather well, but once again, I'm still running into problems getting the alignment to work right. I can create the table, with one row and insert the data into it without issue. However, I still cannot get the alignment of the cell data to work.
Here's some basic code on how I started this plan of attack:
[VBA]
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, 1, 1
set objTable = objDoc.Tables(1)
[/VBA]
This creates my table with 1 row. However, I've tried several methods to get the alignment of the table content to align to the right without success:
[VBA]
Set objSelection = objTable.Row(1).Range.Select
objSelection.ParagraphFormat = wdAlignParagraphRight
[/VBA]
I get the idea I have to select the right object and work with it, I've even run the Macro recorder to make sure I'm not missing anything but when I run my script (saved as foo.vbs) it creates the table, injects the content but does not align the content to the right.
What am I missing?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules