Calling Private Sub/Function

  • Thread starter Thread starter AMK4
  • Start date Start date
A

AMK4

So how can you call a Private Sub or Function? Or is that simply not
possible? I have an OnTime event that needs to call another Sub when
the timer runs out, but that other Sub is private.
 
Norman said:
Hi AMK4

Look at the Run method in VBA help.

I'm a bit confused. How would I use this in an OnTime method?

This is what I'm trying to get to:

My userForm has this on it:
Application.OnTime Now + TimeValue("00:00:05"), "myMacro"

myMacro is a Private Sub defined in the Modules. How would I use
Application.Run instead of calling myMacro?
 
Hi AMK4,

One way:

Sub AAA()
Application.OnTime Now + TimeValue("00:00:05"), "myMacro"
End Sub

Sub myMacro()
Call BBB
End Sub

Private Sub BBB()
MsgBox "Hello"
End Sub
 
Hi AMK4,

In fact, if no parameters are to be passed, the private macro or function
can be called without recourse to the Run method:

Sub AAA()
Application.OnTime Now + TimeValue("00:00:05"),"MyMacro"
End Sub

Or, if the macro is in another workbook:

Sub AAAA()
Application.OnTime Now + TimeValue("00:00:05"), _
"'Another Workbook'!MyMacro"
End Sub

Or, if the macro is in a sheet module of another workbook:

Sub AAAAA()
Application.OnTime Now + TimeValue("00:00:05"), _
"'Another Workbook'!Sheet1.MyMacro"
End Sub
 
Hi AMK4,

And, if parameters are to be passed to the function or macro, then try
something like:

Sub ABC()
Application.OnTime Now + TimeValue("00:00:05"), "BBB"
End Sub

Sub BBB()
MsgBox Application.Run("MyFunction", 2, 3)
End Sub

Private Function MyFunction(var1, var2)
MyFunction = var1 * var2
End Function
 

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

Back
Top