VBA UserForm TextBox As Function Param

Anonymous
2018-06-08T00:25:20+00:00

I have a word 2016 doc and have created a userform with textboxes.

How do I pass a textbox as a parameter. Something like...

Public Function AAA(bbb as textbox)

I dont see a textbox or control type anymore.

Googling is no help

and Word help is even worse.

Thanks

Moved from: Office/Word/Windows 10/Office 2016

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Jay Freedman 206K Reputation points Volunteer Moderator
    2018-06-10T03:28:25+00:00

    Passing controls as arguments isn't something I do, so I had to play with this a bit. It turns out that if you declare a sub or function with a parameter like this:

       Sub Toggle(ByRef ckBox As CheckBox)

    and try to use properties of the object ckBox in the procedure's code, you get (for most of the properties) an error that the object doesn't have any such property, or in some cases you'll get a type mismatch error at run time. It turns out that using just "CheckBox" like that gives you an entirely different kind of object with just a handful of properties.

    Instead, declare it this way:

        Sub Toggle(ByRef ckBox As MSForms.CheckBox)

    and everything works when you call it like

         Toggle CheckBox1

    3 people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2018-06-22T20:15:52+00:00

    That is exactly what I found out. I could not find any documentation anywhere. Now there is.

    Thanks

    0 comments No comments