common module

R

rmanchu

hi guys, need advice on how to best do the following.

i've created a module which i currently manually import to all my
templates. this module contains subroutins and functions (some don't
call any word objects, some do) and publicly declared variables
(strings, ints, Recordsets)

what's the best way to share this module without manually inporting it
into every template i create?

pleasse help.

thanx
riyaz
 
H

Helmut Weber

Hi Riyaz,

put it in the startup-folder.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

Tony Jollans

You can't automagically get a module into a new template - you have to do it
manually.

You could, I suppose, get in the habit of starting your templates based on a
template which contained the module, or ...

If you put it in your normal template then it's a simple click and drag
manual process

Of course, depending on how and by whom your templates are used, you may not
need a copy of the module in every template - it may be good enough to have
it in a global template.
 
J

Jonathan West

The following approaches are possible.

1. Place the modules in a separate template. Place the template in the
startup folder so it is loaded as an add-in when you start Word, and then
call subroutines in those modules by means of the Application.Run method

2. Place the modules in a separate template, have the template located in a
fixed location, and in your other modules go to Tools References in the VBA
editor, and set a reference to that template.

3. If you have a copy of VB6 available, use it to create an ActiveX DLL and
move your code there. In your templates, set a reference to the DLL. Then
the code in the DLL can be used as if it is in a Class module.
 
R

rmanchu

thanx guys, i'm working on the startup folder method, using
Application.Run

syntax getting long but it seems to work.

now ... how to access constants and variables declared in the common
template from other templates?

is this possible? what things do i have to be careful of? eg: if i have
to specific templates that both use the common template then the
variables declared can be corrupted?

thanx
riyaz
 
H

Helmut Weber

Hi Riyaz,

you may pass arguments to functions and subs
in other templates, like:

Application.Run "ProjectX.Modul1.SubNoArgument" ' working alright
Application.Run "ProjectX.Modul1.SubWithArgument", "Text" ' Error 438
Application.Run "SubWithArgument", "Text" ' working alright

It seems, You have to use an application-wide unique name,
when passing arguments to a sub in another template.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

rmanchu

hi helmut

that was not my question.

eg: say i've declared a constant NAME in the global template loaded
from the startup folder.

how do i access it from other templates that i create?
how do i access module level public constants/variables in the global
template?

thanx
riyaz
 
J

Jonathan West

now ... how to access constants and variables declared in the common
template from other templates?

As far as I'm aware, this is not possible for constants.

For variables, using the Application.Run approach, this is also not
possible.
 
H

Helmut Weber

Hi,

I should have been a bit more explicit.
I thought about something like this, e.g.

In normal template:

Sub test89901()
MsgBox Application.Run("Getconst")
End Sub

In another template

Const XName = "Xname"

Public Function Getconst() As String
Getconst = XName
End Function

Or Get the Value of the const

A workaround sure, but gets you the value
of the constant XName from the other template.

Or to get the value of any constant.

MsgBox Application.Run("Getconst2", "XName")

plus:

Const XName = "xxxxxxxxxxxxxxxxxxx"

Public Function Getconst2(sTmp As String) As String
Getconst2 = sTmp
End Function



Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
 

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