VBA call a SUB in a Sheet from module

You need to set your function to Public as shown below

Sheet1:

Public Sub test()
    MsgBox "Got here!"
End Sub

Module:

Sub callTest()
    With Sheet1
        Call .test
    End With
End Sub

for me, I had to change the Sheet Sub Procedure from Private to Public for the Call to work.

Call Worksheets("Sheet_name").Sub_name

In my case:

Call Worksheets("Sheet 20").CommandButton1_Click

If it's in the same project and of Public scope - just use the name of the sub.

If it's in a another workbook, use Application.Run()

1.

Sub Foo()
    Bar '// Runs Sub Bar()
End Sub

Sub Bar()
    MsgBox "I got called!"
End Sub

2.

Sub Foo()
    Application.Run "MyOtherWorkbook.xlsm!Bar"
End Sub

Tags:

Excel

Vba