Accessing Word Constants from Excel

K

Ken Loomis

I needed an Excel macro that would let the user enter information about a
client into a worksheet, then, with the click of a button, open a Word
document that I had built that contained placeholders for the actual
information. All the information from the worksheet needed to be inserted
into the Word document and then the document needed to be printed.

I recorded macros in Word for the replace and print functions. I copied
those to the Excel macros and everything worked fined until it ran into
this:

wdPrintAllPages

which is a Word constant and apparently, there wasn't way to access the
Word constants from an Excel macro.

Is that right? If not, how do I change "wdPrintAllPages" so that it will
return that value in Excel.

I was able to find the value of those in VBE for Word and simply hard coded
them into my macros, but I was wondering if there were a more elegant way to
do this.


Thanks for any suggestions.

Ken Loomis
 
D

Dave Peterson

I have seen lots of code that uses latebinding mimic these values:

Const wdPrintAllPages as long = 0

so that the code is more self documenting.
 
J

Jake Marx

Hi Ken,

There are a few ways to do this. One is the method you used - replacing the
constants with their literal values. Another is to set a reference to the
Word object library via Tools | References. Once Excel has the object
library reference, it will "know" the values of the Word constants.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
K

Ken Loomis

Thanks, Dave. That worked well.


Dave Peterson said:
I have seen lots of code that uses latebinding mimic these values:

Const wdPrintAllPages as long = 0

so that the code is more self documenting.
 
K

Ken Loomis

Thanks for the help, Jake.

Jake Marx said:
Hi Ken,

There are a few ways to do this. One is the method you used - replacing
the constants with their literal values. Another is to set a reference to
the Word object library via Tools | References. Once Excel has the object
library reference, it will "know" the values of the Word constants.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Ken said:
I needed an Excel macro that would let the user enter information
about a client into a worksheet, then, with the click of a button,
open a Word document that I had built that contained placeholders for
the actual information. All the information from the worksheet needed
to be inserted into the Word document and then the document needed to
be printed.
I recorded macros in Word for the replace and print functions. I
copied those to the Excel macros and everything worked fined until it
ran into this:

wdPrintAllPages

which is a Word constant and apparently, there wasn't way to access
the Word constants from an Excel macro.

Is that right? If not, how do I change "wdPrintAllPages" so that it
will return that value in Excel.

I was able to find the value of those in VBE for Word and simply hard
coded them into my macros, but I was wondering if there were a more
elegant way to do this.


Thanks for any suggestions.

Ken Loomis
 

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