A question about Alignment using the Word object

J

Jerry Rhodes

I am using the Word 2000 object to perform a mailmerge from an SQL
Server table. I would like for the upper left corner to contain a JPG
and return address, with the customer address centered below that.
The JPG is being left aligned, but the return address is being
centered. Why is the return address being centered? Here's the code.
Thanks for any help!!

Sub AutoOpen()
ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
Mailing;UID=xjlr;APP=Microsoft®
Query;WSID=W0310011;DATABASE=CheckingNewAcctCallIn;Trusted_Connection=Yes"
_
' , SQLStatement:= _
' "SELECT CheckingNewAcctCallIn.FirstName,
CheckingNewAcctCallIn.LastName, CheckingNewAcctCallIn.Address1,
CheckingNewAcctCallIn.City, CheckingNewAcctCallIn.State,
CheckingNewAcctCallIn.PostalCode FROM
CheckingNewAcctCallIn.dbo.CheckingNewAcctCallIn Checkin" _
' , SQLStatement1:= _
' "gNewAcctCallIn ORDER BY CheckingNewAcctCallIn.LastName,
CheckingNewAcctCallIn.FirstName"
ActiveDocument.MailMerge.OpenDataSource Name:="",
ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=False,
AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="",
WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False,
Format:=wdOpenFormatAuto, _
Connection:= _
"DSN=CheckingNewAcctCallIn;Description=New Checking Acct Info
Mailing;UID=xjlr;APP=Microsoft®
Query;WSID=W0310011;DATABASE=CheckingNewAcctCallIn;Trusted_Connection=Yes"
_
, SQLStatement:= _
"SELECT CheckingNewAcctCallIn.FirstName,
CheckingNewAcctCallIn.LastName, CheckingNewAcctCallIn.Address,
CheckingNewAcctCallIn.City, CheckingNewAcctCallIn.State,
CheckingNewAcctCallIn.Zip, CheckingNewAcctCallIn.PrintNow FROM
CheckingNewAcctCallIn.dbo.Check" _
, SQLStatement1:= _
"ingNewAcctCallIn CheckingNewAcctCallIn WHERE
(CheckingNewAcctCallIn.PrintNow='Y') ORDER BY
CheckingNewAcctCallIn.LastName, CheckingNewAcctCallIn.FirstName"
Application.MailingLabel.DefaultPrintBarCode = False
With ActiveDocument.MailMerge
With .Fields
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.InlineShapes.AddPicture FileName:="D:\Bank.jpg",
LinkToFile:= _
True
Selection.TypeText Text:=vbCrLf
Selection.Font.Bold = True
Selection.Font.Size = 10
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeText Text:="PO Box 11, ReturnCity, CO 80123"
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:=vbCrLf
.Add Range:=Selection.Range, Name:="FirstName"
Selection.TypeText Text:=" "
.Add Range:=Selection.Range, Name:="LastName"
Selection.TypeText Text:=vbCrLf
.Add Range:=Selection.Range, Name:="Address"
Selection.TypeText Text:=vbCrLf
.Add Range:=Selection.Range, Name:="City"
Selection.TypeText Text:=", "
.Add Range:=Selection.Range, Name:="State"
Selection.TypeText Text:=" "
.Add Range:=Selection.Range, Name:="Zip"
Selection.TypeText Text:=vbCrLf
End With
Dim oAutoText As Word.AutoTextEntry
Set oAutoText =
NormalTemplate.AutoTextEntries.Add("LabelLayout",
ActiveDocument.Content)
ActiveDocument.Content.Delete
Application.MailingLabel.CreateNewDocument Name:="5163",
Address:="", _
AutoText:="LabelLayout",
LaserTray:=wdPrinterDefaultBin
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
oAutoText.Delete
End With
ActiveDocument.Close False
Application.Visible = True
Application.NormalTemplate.Saved = True

End Sub
 
H

Helmut Weber

Hi Jerry,
you are in paragraph(x) and set it's alignment to left.
Selection.Font.Bold = True
Selection.Font.Size = 10
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeText Text:="PO Box 11, ReturnCity, CO 80123"
You are still in paragraph(x) and set it's alignment to center.
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:=vbCrLf
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
P

Peter Hewett

Hi Jerry Rhodes

The text is being centered because your code is centering it:
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

When you insert a new paragraph, or in your case do it programmatically:
Selection.TypeText Text:=vbCrLf

Word take the formatting of the current paragraph and uses it for the next, so
it carries the Centering forward. Try changing:

Selection.TypeText Text:=vbCrLf
.Add Range:=Selection.Range, Name:="FirstName"
Selection.TypeText Text:=" "
to:

Selection.TypeText Text:=vbCrLf
.Add Range:=Selection.Range, Name:="FirstName"
Selection.TypeText Text:=" "
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

HTH + Cheers - Peter


(e-mail address removed) (Jerry Rhodes), said:
 
J

Jerry Rhodes

Peter -- thanks a bunch!!! Seems a bit goofy to me, but hey, it works
so I'm not complaining. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top