2

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*?

FreeSoftwareServers
  • 2,271
  • 1
  • 33
  • 57
  • Absolutely to be honest. I revised a deleted post to hopefully get myself out of a question ban and posted the solution to my question. Hopefully thought the screenshots will help others understand the issue. – FreeSoftwareServers Oct 26 '19 at 12:14
  • Seems that using the word Call has caused your Q to be misunderstood. If you edit the Q to make it clear what you actually mean (include that your Module and Function names were the same) I'll consider reopening – chris neilsen Oct 28 '19 at 20:20

1 Answers1

1

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!

enter image description here

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:

enter image description here

I will generally just append _Sub to my module names to avoid this issue like below:

enter image description here

Also a note about using the keyword Call.

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

See here for more information --> What does the Call keyword do in VB6?

Community
  • 1
  • 1
FreeSoftwareServers
  • 2,271
  • 1
  • 33
  • 57