Adding ActiveX events to Word doc/project from VB6

V

vera

Can someone help me with this problem or at least guide me
in the right direction?

I'm creating a Word document in VB6. I'm pretty sure that
I can add the forms ActiveX components to the Word
document, although I haven't worked out the syntax yet.

Now how do I add a code module or the event code for the
components to the Word document from VB6? I can't seem to
find a module object and I'm thinking maybe the modules
aren't really associated with the document, but with the
document's project? Am I correct? Am I confused? Please
help, I'm just really new at this Word VBA thing.
 
T

Thomas Winter

vera said:
Can someone help me with this problem or at least guide me
in the right direction?

I'm creating a Word document in VB6. I'm pretty sure that
I can add the forms ActiveX components to the Word
document, although I haven't worked out the syntax yet.

Now how do I add a code module or the event code for the
components to the Word document from VB6? I can't seem to
find a module object and I'm thinking maybe the modules
aren't really associated with the document, but with the
document's project? Am I correct? Am I confused? Please
help, I'm just really new at this Word VBA thing.

You are on the right track. What you want is, I believe, the VBProject
property of the Document object. Then look at the VBComponents property of
the VBProject. Modules are represented by VBComponent objects, just of the
type module (rather than class, etc.). Study the help file. You can easily
import modules from text files, but building procedures, etc. at run time
might not be too easy. (I haven't done it though....)

-Tom
 
P

Perry

Here's a simple example:

Add a commandbutton from the ActiveX Toolset to the document.

Add a classmodule to yr project and call it: MyBtn
Enter following code in the classmodule

Public WithEvents ctl As CommandButton

Private Sub ctl_Click()
MsgBox "Hello World"
End Sub

Enter following code in ThisDocument module:

Dim btn As MyBtn

Private Sub Document_Open()
Set btn = New MyBtn
With ActiveDocument
Set btn.ctl = .InlineShapes(1).OLEFormat.Object
If .FormsDesign Then .ToggleFormsDesign
End With
End Sub

Save the document, and open it.
Click on commandbutton to see whether it works.

Krgrds,
Perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top