Click to See Complete Forum and Search --> : VBScript and Word : using Mailing.CustomLabels


Olivier591
December 17th, 2003, 01:19 PM
Hi,

I created a VB Script which open Word and Merge Data from a file.
To do this script, I used MS Kb article 285176

My code looks like this


Function doReport()
Dim wrdApplication
Dim wrdDocument
Dim oMergedDoc

'msgbox "Ouverture de Word"
Set wrdApplication = CreateObject("Word.Application")

wrdApplication.DisplayAlerts = False

' Add a new document.
Set wrdDocument = wrdApplication.Documents.Add
With wrdDocument.MailMerge
'Police et Taille
wrdApplication.Selection.Font.Name = "Arial"
wrdApplication.Selection.Font.Size = 12
'Add our fields.
.Fields.Add wrdApplication.Selection.Range, "CORRESPONDANT"
wrdApplication.Selection.TypeParagraph
.Fields.Add wrdApplication.Selection.Range, "SOCIETE"
wrdApplication.Selection.TypeParagraph
.Fields.Add wrdApplication.Selection.Range, "ADRESSE"
wrdApplication.Selection.TypeParagraph
.Fields.Add wrdApplication.Selection.Range, "VILLE"
wrdApplication.Selection.TypeParagraph
.Fields.Add wrdApplication.Selection.Range, "PAYS"
wrdApplication.Selection.TypeParagraph

'Create an autotext entry.
Dim oAutoText
Set oAutoText = wrdApplication.NormalTemplate.AutoTextEntries.Add("MyLabelLayout", wrdDocument.Content)
wrdDocument.Content.Delete
.MainDocumentType = 1 ' 1 = wdMailingLabels

'Open the saved data source.
.OpenDataSource "F:\ASP\data.txt", ,False

'Create a new document.
wrdApplication.MailingLabel.CreateNewDocument "5163", "", "MyLabelLayout", , 4 ' 4 = wdPrinterManualFeed

.Destination = 0 ' 0 = wdSendToNewDocument
'Execute the mail merge.
.Execute

oAutoText.Delete
End With

' Close the mail merge edit document.
wrdDocument.Close False
' Get the current document.
wrdApplication.Visible = True
Set oMergedDoc = wrdApplication.ActiveDocument

err.clear
Set wrdDocument = nothing
Set oAutoText = nothing
Set oMergedDoc = nothing
Set wrdApplication = nothing
doReport = True
End Function


I would like to use Mailing.CustomLabels properties to use my own labels
I think the code could be like this


Set myLabel = wrdApplication.Mailing.CustomLabels.Add("MonEtiquette", False)
With myLabel
.Height = CentimetersToPoints(5.2)
.Width = CentimetersToPoints(7)
.HorizontalPitch = CentimetersToPoints(7.62)
.VerticalPitch = CentimetersToPoints(5.93)
.NumberAcross= 2
.NumberDown = 4
.PageSize = 4
.SideMargin = CentimetersToPoints(3.19)
.TopMargin = CentimetersToPoints(3.36)
End With


and I replace "5163" by "MonEtiquette" in .CreateNewDocument action

But nothing append.
If someone have an idea.
Regards
Olivier

PS: sorry for my english, but I'm french

Olivier591
December 18th, 2003, 07:12 AM
I find the soluce.

the command is

MailingLabel.CustomLabels

ant not

Mailing.CustomLabels

Bye