VBA Code to Access Another Project

S

singeredel

How do I write code to access and run a procedure in a module in another
project. When the project template is opened in the Visual Basic Editor, it
appears as follows:

Julie(JuliePersonal), with Julie being the project name and (JuliePersonal)
being the open template. I need to write code to run a procedure in the Julie
project from the Normal template.

I have tried many things, including the following:

With Julie.VBProject
CreateReport.CreateReport
End With

(CreateReport being the module and .CreateReport being the procedure)

However, I get a run-time error 424: Object required.
 
J

Jezebel

Open and activate the JuliePersonal project. In VBE, go to Tools >
References. Check the box alongside Julie.

Then in your code you can use: Julie.[ModuleName].CreateReport

[ModuleName] is the name of the code module containing the CreateReport
function.
 
S

singeredel

I am trying to access the Julie project from the Normal template project. I
previously tried creating a reference to Julie in the Normal project, but I
get an error that "Cyclic reference of projects is not allowed." I have a
reference to Normal in the Julie project to access a module in the Normal
project from the Julie project. Now I need the reverse to happen -- to be
able to access a module in Normal from Julie.

Jezebel said:
Open and activate the JuliePersonal project. In VBE, go to Tools >
References. Check the box alongside Julie.

Then in your code you can use: Julie.[ModuleName].CreateReport

[ModuleName] is the name of the code module containing the CreateReport
function.




singeredel said:
How do I write code to access and run a procedure in a module in another
project. When the project template is opened in the Visual Basic Editor,
it
appears as follows:

Julie(JuliePersonal), with Julie being the project name and
(JuliePersonal)
being the open template. I need to write code to run a procedure in the
Julie
project from the Normal template.

I have tried many things, including the following:

With Julie.VBProject
CreateReport.CreateReport
End With

(CreateReport being the module and .CreateReport being the procedure)

However, I get a run-time error 424: Object required.
 
S

singeredel

Sorry, my last sentence was wrong -- I need to now access the Julie project
from the Normal project.

Thx...

Jezebel said:
Open and activate the JuliePersonal project. In VBE, go to Tools >
References. Check the box alongside Julie.

Then in your code you can use: Julie.[ModuleName].CreateReport

[ModuleName] is the name of the code module containing the CreateReport
function.




singeredel said:
How do I write code to access and run a procedure in a module in another
project. When the project template is opened in the Visual Basic Editor,
it
appears as follows:

Julie(JuliePersonal), with Julie being the project name and
(JuliePersonal)
being the open template. I need to write code to run a procedure in the
Julie
project from the Normal template.

I have tried many things, including the following:

With Julie.VBProject
CreateReport.CreateReport
End With

(CreateReport being the module and .CreateReport being the procedure)

However, I get a run-time error 424: Object required.
 
T

Tom Winter

This might not apply directly, but I thought these examples I wrote up for
another post might help you out:

To access "macros" in an add-in (global) template, you do not need to add a
reference
to it for the current document/project. The following are equivalent:

### Example 1 ###

' MyProject.ThisDocument has had a reference added to the template
Macros.dot. In this case, Macros.dot does not need to be loaded as an add-in
(global) template.

Sub Test

MacrosProjectName.ModuleName.PublicRoutineName x, y, z ' You don't
really need to include .ModuleName, but you can if you want.

End Sub

### Example 2 ###

' Macros.dot is loaded as an add-in (global) template, either by the user
from TOOLS | TEMPLATES AND ADD-INS, by code, or by being in the STARTUP
folder.

Sub Test

Application.Run "PublicRoutineName", x, y, z ' Application.Run in
Word 2000 or later will return the return value from the routine.

End Sub

### Example 3 ###

' The document has it's attached template set to Macros.dot

Sub Test

MacrosProjectName.ModuleName.PublicRoutineName x, y, z ' You don't
really need to include .ModuleName, but you can if you want.

End Sub

####
 
S

singeredel

Thank you so much for your reply. I am either not understanding what you have
written or something else is going on. I have tried the following code:

AddIns("C:\Julie-Personal\Word Templates\Master
Template\JuliePersonal.dot").Installed = True

Application.Run MacroName:="Julie.Create_Julie_Report.Create_Julie_Report"

(I have also tried: Julie.Create_Julie_Report.Create_Julie_Report and just
plain Julie.Create_Julie_Report)

I have installed the template "JuliePersonal.dot" as per above. I am trying
to run the procedure listed above from the Normal project but I am getting a
run-time error '-2147352573(8002003)" indicating "unable to run specified
macro" or "Object required."

I have a reference to "Normal" in my "Julie" project because I also need to
access a module in the Nomal template when using the "Julie" project and it
would not run that procedure until I added a reference to Normal.

If the "Julie" template is installed, why wouldn't everything in that
template be available from any project? Is there some place where you have to
indicate that the module is "Public?"

Thanks!
 

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