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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using named constants in VBScript

Status
Not open for further replies.

megmoo75

Programmer
Jun 14, 2003
40
0
0
US
I am attempting to do a mail merge from Excel to a Word template via vbscript in a DTS package. Since named constants don't work in vbscript, I need to know how to reference to constants properly in vbscript.

Here is the statement I want to execute:

If doc.MailMerge.State = wdMainAndDataSource Then .Execute

Since wdMainAndDataSource is a named constant that can't be used in VBScript, I attempted to do this as instructed on the MSDN website:

If doc.MailMerge.State = doc.MailMerge.Constants.wdMainAndDataSource Then .Execute

But this gives me an error stating "Object doesn't support this property or method: 'doc.MailMerge.Constants'

I can reference other properties of doc.MailMerge such as doc.MailMerge.DataSource.FirstRecord, but not the constants.

Any ideas?
 
You could just define your own variables and use them as long as you know what the value of each constant is.

Example:

dim wdMainAndDataSource=1

then use your:

If doc.MailMerge.State = wdMainAndDataSource Then .Execute




MrGreed

"did you just say Minkey?, yes that's what I said."
 
Thanks - this is what I've ended up doing (though I just used the value rather than creating the variable). I just figured there might be a way to get the named constants to work like it says it should on MSDN.

Thanks for your help!!

 
Yeah MSDN is hit or miss with there solutions, I think if your operating in the exact environment that MSDN said the code will work then it will work but any little deviation it's fifty fifty.

You might want to conside using variables because 6 months down the road you may not remmber what 1 means when looking at the code unless you have commented each area, also if the value ever changes you only have to change it in one spot instead of every where you used the value.

Just my 2 cents

MrGreed

"did you just say Minkey?, yes that's what I said."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top