I have been copying code moslty to work on and learn macro's in Word. I have got it working where I can get a MsgBox to appear before printing, but I would like it to call another module/macro to compartmentalize the modules.
For testing, this works:
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
MsgBox "Before Print"
End Sub
But if I do:
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Call Greeting
End Sub
Which is a working macro that I have which simple opens a MsgBox and says "Greetings", I get the following error:
Compile Error: Expected variable or procedure, not module
How can I call another Macro inside this Private Sub App*?
While this post has been covered before, I will share the answer here as well in case others land here.
The issue is that you can't have a module named the same as a sub. See Screenshot below for what is WRONG!
Interestingly, if you put the sub that calls the other sub (greeting) inside the same module (greeting) it works! But I would say this is bad practice and should be avoided. See example below:
I will generally just append
_Subto my module names to avoid this issue like below:Also a note about using the keyword
Call.See here for more information --> What does the Call keyword do in VB6?