Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA - Call Private Sub on userform from module

Status
Not open for further replies.

hermanlaksko

Programmer
Aug 26, 2001
937
DK
I have tryed:
Application.Run UserFormName & "." & "Private Sub Cmd_Save_Click"
But get the error msg: Unable to run the specified macro
I know that the Sub is there and Application.Run should do the trick.
So what am I doing wrong or cat this be done owing to the fact that this is a private sub ?

Herman
Say no to macros
 
>I know that the Sub is there and Application.Run should do the trick.

Application.Run basically cannot call class methods. And a form is a class ...

CallByName works, though, but the first parmeter needs to be the object in question, not a string (but that's OK, becasue we've covered how to get to the form object from string name in thread707-1783526)

CallByName UserForm1, "CommandButton1_Click", VbMethod
 
Or you can do this ( I think.... I hope....):

Code:
Option Explicit
...
Private Sub Cmd_Save_Click()
Call [blue]MySaveMagic[/blue]
End Sub
...

and in the standard Module:

Code:
Option Explicit
...

Public Sub [blue]MySaveMagic[/blue]()[green]
    'My code to save stuff...[/green]
End Sub
...

Then you just do: [tt]Application.Run [blue]MySaveMagic[/blue][/tt]


---- Andy

There is a great need for a sarcasm font.
 
> I think.... I hope....

oops ... it would be

Application.Run "MySaveMagic"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top