Running a module in a macro

C

ChuckW

Hi,

I want to run a module in a macro. The macro is the autoexec and I want to
schedule it for early in the morning. I only have one module called Module1.
If I open it and press the play button it works. There is not step in macros
that I saw called RunModule. I see OpenModule but I want to actually have it
run the module. Can anyone help?

Thanks,
 
M

Marshall Barton

ChuckW said:
I want to run a module in a macro. The macro is the autoexec and I want to
schedule it for early in the morning. I only have one module called Module1.
If I open it and press the play button it works. There is not step in macros
that I saw called RunModule. I see OpenModule but I want to actually have it
run the module.


You don't "run" a module. A module is a container for a
collection of Procedures (either Sub or Function).

The way to run a **Function** procedure is to use the
RunCode action in the macro.

You can not run a Sub procedure from a macro. If that's
what you were trying to do, then you have to either change
it to a Function or create a Function procedure that calls
the Sub procedure.
 
F

fredg

Hi,

I want to run a module in a macro. The macro is the autoexec and I want to
schedule it for early in the morning. I only have one module called Module1.
If I open it and press the play button it works. There is not step in macros
that I saw called RunModule. I see OpenModule but I want to actually have it
run the module. Can anyone help?

Thanks,

It's called RunCode, not RunModule.
 
C

ChuckW

Marshall,

Thanks for your help. I am a real VBA novice. Someone sent me come vba
code and I created a module out of it called Module1. Here are the first few
lines of code:

Public Sub testCDO()
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
 
M

Marshall Barton

ChuckW said:
Thanks for your help. I am a real VBA novice. Someone sent me come vba
code and I created a module out of it called Module1. Here are the first few
lines of code:

Public Sub testCDO()
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields


Yes it is.

You do need to have at least a vague idea of what it does
and how it does it. I can tell from your excerpt that it is
doing something I have never tried to do, so there's no hope
that I can help you unravel it. About all I can say is that
it looks like it probably won't make any difference if you
change it from a Sub to a Function. Just change the line:
Public Sub testCDO()
to
Public Function testCDO()
The related changes in the End and any Exit statements
should be taken care of automatically.

The next thing you should do is is use the Debug - Compile
menu item (when viewing the module) to make sure it compiles
without error. If it doesn't then you will need to fix
whatever is wrong.

Once it compiles without error, you can test it. This
should be very straight forward since it worked before you
made any changes.
 

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

Top