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