0

I have a VBA application written in Excel that opens Word documents and manipulates them.

I believe I want to use Late Binding because:

  1. I don't want the user to have to add the reference library
  2. I don't know what version of Excel / Word they are on anyway.

So to use late binding, I understand you must first declare the object "as Object":

Dim oWordApp As Object
Dim oActiveDoc As Object
Dim oSection As Object
Dim oSections As Object
Dim oTable As Object
Dim oTables As Object

Then, in the procedure, create the objects with the appropriate library reference:

Set oWordApp = CreateObject("Word.Application")
Set oActiveDoc = CreateObject("Word.Document")
Set oSection = CreateObject("Word.Section")
Set oSections = CreateObject("Word.Sections")
Set oTable = CreateObject("Word.Table")
Set oTables = CreateObject("Word.Tables")

This approach works for oWordApp and oActiveDoc objects. It fails at oSection and beyond.

When I'm able to trap an error, it's a 429 error.

Any ideas? (By the way, there more Word objects needed, just not shown for brevity. Also, I need to extend this approach to Visio objects used within Excel VBA once I figure it out.

Thanks

0

1 Answer 1

2

You only need CreateObject for the Application. Once you've created an instance of Word, then use oWordApp to create new documents, manipulate tables and sections, and so on.

Set oWordApp = CreateObject("Word.Application")
Set oActiveDoc = oWordApp.Documents.Add()

and so on.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I got this t work (generally). I found that within called routines I needed to declare my objects "as Objects": "code"
Hit the timeout on comments. @BigBen Thanks. I got this to work (generally). I found that within called routines I needed to declare references "as Objects": i.e. [code] Private Sub Word_Replace_Cover_Graphics(oSection As Object) [code] rather than oActiveDoc.Section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.