Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA call a SUB in a Sheet from module

Tags:

excel

vba

I am trying to call a Sub I defined inside a Sheet, from a Module.

The code I use in my Module (which happens to be inside a Sub):

CallByName Worksheets("Sheet_name"), "Sub_name", vbMethod

But Excel does not execute the Sub. The Module and Sheet are inside the same workbook.

like image 467
user3614882 Avatar asked Nov 20 '15 16:11

user3614882


1 Answers

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
like image 69
Estevam Garcia Avatar answered Sep 20 '22 13:09

Estevam Garcia