ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Accessing Word constants in Excel (https://www.excelbanter.com/excel-programming/314677-accessing-word-constants-excel.html)

Ken Loomis

Accessing Word constants in Excel
 
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



Dave Peterson[_3_]

Accessing Word constants in Excel
 
If you set a reference to Word in your excel macro, you can use word's
constants.

But you may just want to replace that constant with its value.

Open word, go into the VBE (inside word)
hit ctrl-g (to see the immediate window)

type
?wdprintallpages

(I got 0)

And you'll see what that constant evaluates to.

If you have lots to do, you could hit F2 (inside's word VBE) and use the object
browser to search for your constants.

Ken Loomis wrote:

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


--

Dave Peterson


Dave Peterson[_3_]

Accessing Word constants in Excel
 
And by using a reference to a specific version of Word, you may have trouble if
you have users who are not running the same version.

I'd develop with the reference, then change to late binding before releasing the
workbook to others.

Ken Loomis wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com