Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the list of available Label formats from MS Word

Status
Not open for further replies.

wgcs

Programmer
Mar 31, 2002
2,056
EC
Does anyone know how to programmatically get the list of available label formats from Microsoft Word through ActiveX Automation?

The ones I need are the predefined label formats, not the custom label formats.

(The custom label formats are available through the WordApp.MailingLabel.CustomLabels collection... in a new installation there are no custom label formats, but there ARE a TON of Avery, FormTec, Xerox, and other formats)

I want to present my users with a list of label formats for them to pick from, then My program will automate word and produce the labels in the right format. I want to avoid manually copying all the format names into a table, etc, plus, if MS Word adds more label formats, I want them to automatically show up.
 
Here is the information I found in the VBAWD10.CHM file (The help file for Microsoft WORD 2002).

DefaultLabelName Property
Returns or sets the name for the default mailing label. Read/write String.

Note To find the string for the specified built-in label, select the label in the Label Options dialog box (Tools menu, Envelopes and Labels dialog box, Labels tab, Options button). Then click Details and look at the Label name box, which contains the correct string to use for this property. To set a custom label as the default mailing label, use the label name that appears in the Details dialog box, or use the Name property with a CustomLabel object.

Remarks
Creating a new label document from a CustomLabel object automatically sets the DefaultLabelName property to the name of the CustomLabel object.

Example
This example returns the name of the current default mailing label.

(Msgbox Application.MailingLabel.DefaultLabelName) && VB code
Translated in to FoxPro:
MESSAGEBOX(TRANSFORM(oWord.MailingLabel.DefaultLabelName))

This example sets the Avery Standard, 5160 Address label as the default mailing label.

oWord.MailingLabel.DefaultLabelName = "5160"

I realise this does not give you the list of all available labels, but it's a start.

 
Thanks for looking... I found the same statement, and have so far pursued the course of creating a table filled with all the Avery Standard label formats (what it doesn't tell you but that I demonstrated by experiment, is that this string to use is the first part of the display string in the Label Options dialog's listbox... that is, the part of the string before " - ", so I just made a list of all these.)

The one remaining trouble is my App will now support every built-in label format for Word 2000 ... what if my user has Word 97? Or Word XP? '97 will probably support fewer formats and 'XP probably supports more... it'd be nice for it to automatically present the formats that the installed version of Word supports.
 
Yes, there must be a way to retreive that list from Word. Still looking.

BTW VFP has it's own list of avery label (located on my system @ "d:\microsoft visual foxpro7.0\tools\addlabel\labels.dbf" )
You could use that table to let the user select a lable type and store the :
STORE SUBSTR(labels.name,6,4) to nLabelType
oWord.MailingLabel.DefaultLabelName = (nLabelType)

 
Surprisingly, (maybe not) Word supports many more (though VFP may have added some in the final release, I only have the DevCon pre-release vfp7): Word lists 193 Standard Avery formats, VFP has 86. Not that anyone is likely to need every one, but, it's interesting.
 
wgcs

Although I guess you can create custom labels with the "missing avery labels". Although I guess if 86 is enough labels...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top