PDA

View Full Version : Automation of Word Class



Adamski
05-13-2010, 06:17 AM
Hi,

In a word template I have created a Class called "ThisApplication". It has a boolean property called "DisableEvents".

How/Can I set the "DisableEvents" property of my Class from Excel?

ThisDocument Code
Option Explicit

Dim WordApplication As ThisApplication

Private Sub Document_New()
' Assign WordApplication to the ThisApplication class
Set WordApplication = New ThisApplication
End Sub

ThisApplication Code
Option Explicit

Public DisableEvents As Boolean

Tommy
05-14-2010, 10:01 AM
It depends completely and totally how you have defined Word in Excel.
In Excel if you have:

Dim Wrd as Word.Application


When you add the document you should be able to access the variable as:

Wrd.WordApplication.DisableEvents = True


A note of warning about your variable naming convention. You have WordApplication, this is so similar to Word.Application, this to me is asking for trouble. Looking for the dot in all the lines of code to debug your program will be a nightmare by itself.

fumei
05-17-2010, 11:28 AM
I agree. Better to use very clear names that are different from any built in standard names.

Adamski
07-20-2010, 02:18 AM
Turns out the Class property must have Instancing set to PublicNotCretable and an instance of the class has to be returned from a Word Function, called from Excel.