Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing standard VBA word enumerations

Tags:

ms-word

excel

vba

I'm new to VBA. Some tutorials tell me to use enumeration constants such as wdOrientLandscape and wdRowHeightExactly (to change page orientation and make row height 'exact' respectively). However, when debugging, I can see that the value of these constants is Empty and they don't 'work' as expected.

Do I need to do something special to access these constants e.g. add a reference or something?

I'm creating a Word document from an Excel macro.

Thanks in advance

like image 789
user3586058 Avatar asked Sep 30 '22 21:09

user3586058


1 Answers

Within Excel (or any automation client) the enumerations belonging to the Word object model are not exposed if you use Late Binding (CreateObject("Word.Application")).

If you early bind by adding a reference they become visible.

If you add Option Explicit to the top of you code modules (or select Require Variable Declarations from the VBA editor options) you will receive a compile time warning if you attempt to use something that's not declared/unavailable

In your particular case, you would want to add the Microsoft Word Object Library to your references. If you choose to early bind. This can be done by going to Tools>>References and checking the appropriate box.

like image 114
Alex K. Avatar answered Oct 03 '22 10:10

Alex K.