Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Referencing ActiveX controls

5 views
Skip to first unread message

Geoff & Cynthia Sutton

unread,
Jun 10, 2002, 12:15:50 PM6/10/02
to
I recently was given this code fragment:

> Dim oTextBox As MSForms.TextBox
> Set oTextBox = ActiveDocument.InlineShapes(1).OLEFormat.Object
> MsgBox oTextBox.Text

to enable me to reference the various controls in my Word document from VB
5. I have been searching the reference libraries for the object MSForms,
but am unable to find it. Can anyone tell me which library collection it is
in?

Thanks,

Geoff


ibby

unread,
Jun 10, 2002, 1:16:19 PM6/10/02
to
Hi Geoff,

You can either:

(1) Declare it as a generic object

Dim oTextBox As Object

(2) Set a reference to the "Microsoft Forms 2.0 Object Library" and use:

Dim oTextBox As MSForms.TextBox

If you can't see this library in your list of references, click browse on
the Reference dialog then navigate to and select
"C:\Windows\System32\FM20.dll".


--
Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.


"Geoff & Cynthia Sutton" <Cynn...@Hotmail.com> wrote in message
news:Wg4N8.9989$vo2.2...@news2.telusplanet.net...

ibby

unread,
Jun 10, 2002, 2:17:52 PM6/10/02
to
Geoff,

Another thing - as I said in my original reply, the ActiveX controls may be
part of the Shapes or InlineShapes collection. The default placement of
these controls varies with the version of Word. You should try Shapes(1)
instead of InlineShapes(1) if VB complains that it can't find the textbox.


--
Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.

"ibby" <ib...@bigpond.net.au> wrote in message
news:O8HO7XKECHA.2444@tkmsftngp05...

Geoff & Cynthia Sutton

unread,
Jun 10, 2002, 3:35:44 PM6/10/02
to
Ibby,

I've already done that. I am now able to detect that there are shapes
there, but am finding no way to reference them. Using the oleformat.object
is just getting me type mismatches, and if I declare oTextBox as an object,
I am not able to reference the text property.

Using the shapes collection, I am printing out the names of the controls,
which are declared by word to be Control97 through to Control127 or
something like that. Also, the item(x).type is coming across as a long with
a value of 12 for all controls, labels and textboxes alike.

I don't believe that I am forcing Word to try to do something it's not
equipped for (and it sure bears ProWrite circa 1980!), but they should make
it simpler than this. If I give a control a name inside Word, couldn't Word
at least have the decency you keep that name with that control?

P.S. any suggestions for that curious kink in the back of the neck which
occurs after 14 consecutive hours in front of a laptop? (lol)

Any suggestions you may have would be greatly appreciated. Thanks.

G


----- Original Message -----
From: "ibby" <ib...@bigpond.net.au>
Newsgroups: microsoft.public.word.word97vba
Sent: Monday, June 10, 2002 12:17 PM
Subject: Re: Referencing ActiveX controls


"ibby" <ib...@bigpond.net.au> wrote in message

news:#OpHFsKECHA.2884@tkmsftngp04...

ibby

unread,
Jun 10, 2002, 11:20:22 PM6/10/02
to
Geoff,

Lets start again :-) BTW, What version of Word are you using ?

(1) Create a new blank document and place one ActiveX TextBox in it. Save it
to "C:\Test\Doc1.doc"

(2) Create a new VB project. Add References to
- "Microsoft Word 9.0 Object Library" (or whichever corresponds to
your version of Word)

(3) Place the following code in a module in the VB project. Run it and let
me know what happens.

---------------------------------------------------

Public Sub Main()

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTextBox As Object

Set oWord = New Word.Application
Set oDoc = oWord.Documents.Open("C:\Test\Doc1.doc")
Set oTextBox = oDoc.Shapes(1).OLEFormat.object

oWord.Visible = True

oTextBox.Text = "Hello"

Set oDoc = Nothing
Set oWord = Nothing

End Sub
---------------------------------------------------

Geoff & Cynthia Sutton

unread,
Jun 11, 2002, 12:33:52 AM6/11/02
to
Don't know what's happening here, Ibby.
Compiles fine, but get a type mismatch error when it tries to assign the
shapes object to oTextBox. Maybe a variant?

G


"ibby" <ib...@bigpond.net.au> wrote in message

news:eCJtNbPECHA.2456@tkmsftngp02...

Geoff & Cynthia Sutton

unread,
Jun 11, 2002, 12:40:12 AM6/11/02
to
My mistake. It worked. Now I just have to expand this into 23 objects.
And write supporting code to transfer the data. And present a preview.
And...

Well, anyhow, thank you so very, very much ibby. I owe you one. Or
several. Scream if you want or need some code written.

G.

"ibby" <ib...@bigpond.net.au> wrote in message

news:eCJtNbPECHA.2456@tkmsftngp02...

0 new messages