Microsoft word Object Early/Late Binding

rjtaylor

New Member
Joined
Jan 27, 2004
Messages
36
I write code at home and work. Home computer needs Microsoft Word 15.0 Object Library. When I program at work the reference changes to Microsoft Word 16.0 Object Library. Then the program hangs when back at home.
After searching I learned that I should use Late binding. The problem is that in late binding I get an error when setting the footer but it goes away with the reference set.
Code:
Dim myRange

'Early Binding
Dim wApp As Word.Application
Dim wDoc As Word.Document

Set wApp = CreateObject("Word.application")
Set wDoc = wApp.Documents.Add

'Late Binding
'Dim wApp As Object
'Dim wDoc As Object
'
'Set wApp = CreateObject("Word.Application")
'Set wDoc = wApp.Documents.Add
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
When using late binding, you need to use values instead of constants. For example, here are the corresponding values for the WdHeaderFooterIndex enumeration...

Code:
[U]Constants ===> Values
[/U]
wdHeaderFooterEvenPages ===> 3 
wdHeaderFooterFirstPage ===> 2
wdHeaderFooterPrimary ==> 1

Hope this helps!
 
Upvote 0
When using early binding, you should always compile the project on the earliest Office version you're supporting.

If that's not an option, you can develop code using early binding, then convert to late binding for deployment. As Domenic said, you need to use values instead of constants when using late binding. That said, you can continue to use the early binding names in your code if you declare them beforehand. Taking his WdHeaderFooterIndex values as an example, you might insert:
Const wdHeaderFooterPrimary As Long = 1
Const wdHeaderFooterFirstPage As Long = 2
Const wdHeaderFooterEvenPages As Long = 3
at the top of your code. In the body of your code, you could then keep using those constant names with late binding just as you'd been doing with the early binding.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top