Horace
Horace

Reputation: 342

Working with Userforms from another workbook

I have an add-in that is protected by my company. My goal is to write some VBA to automate much of the clicking around the add-in. Much of the code in there revolves around what is entered in to userforms so the method I am trying now is to write code to work with those userforms instead of rewriting their code to not use the userforms.

The add-in has a macro in one of the modules that opens the userforms. So I just use that to open the userform, which is not a problem. But how do I access the functions within the userforms? I need to do that to simulate the clicking on the userform.

Upvotes: 0

Views: 1655

Answers (1)

Scarfe
Scarfe

Reputation: 418

You can access functions within a user form using the format you have mentioned previously in your comments above. For the sake of providing a complete answer, that is:-

WorkbookName.FormName.FunctionName

However, for this to work the function of concern must be declared as public from within its own code. An example:

Public Function ExampleF(Param1 As Integer)
' Function code
End Function

If you then wanted to set Param1 from outside of your user form, you could use the format FormName.ExampleF(123).

This would set Param1 = 123, and your function could continue to use this value for its code.

Unfortunately if the user form that you are trying to access has not declared its functions as public, I'm afraid they are only accessible by the form itself and there is not much else you can do.

Your best hope would be to attempt to rewrite the add-in completely, or ask that it is unprotected for the purpose of making the functions public.

Upvotes: 1

Related Questions