Hello Jack et al,
Here's an update on toolbars in MS project and using VBA. I have
spent the most part of the last week testing, finding new issues, re-
testing, etc. This could act as a bit of a dummies guide, 'cause I
think while some of this is basic, the information is not readily
found anywhere.
1. When creating a permanent toolbar, you must ensure that all the
relevant modules are copied across to the Global.MPT. If the modules
aren't copied across then the toolbar remains but the buttons will not
appear. For example, if you remove one of the modules from the
Global.MPT then the relevant button will automatically and immediately
disappear from the toolbar. Sounds straightforward, I know, but for a
rookie like me, important to know.
2. The examples Rod gives in his VBA book regarding the use of Excel
are great; however, they cannot necessarily be applied across the MS
suite. I have a requirement to generate a Word document. I thought I
would apply the same logic when using Excel to extract data into
Word. On the face, it works perfect until you want to use the
toolbar.
The following global declaration is made in my module
Option Explicit
Dim wordApp As word.Application
When executed from the local .mpp file the toolbar exists with a
button referencing the appropriate procedure. As soon as the .mpp
file is closed, the button is removed from the toolbar even though the
module and procedures exist in the Global.MPT file. Given what I
stated above in point 1 this doesn't make sense.
After much mucking around and testing I concluded that the above
global declaration is not supported outside the local .mpp file. When
I move the declaration inside the procedure there is no problem; when
the .mpp file is closed, the relevant button remains in place on the
toolbar with no projects open. The only trouble with this is that if
you have modular code that draws on the global declaration then the
code will not work.
As is done for Excel using early binding on the application, the
following line is used.
Set wordApp = GetObject(, "word.Application")
However, I have a recursive procedure that drills through the project
and extracts relevant data and writes the data into Word. However,
because the "wordApp" declaration is now local, the recursive
procedure does not recognise the wordApp variable. If I try to pass
the wordApp variable as a parameter to the recursive procedure, this
does not work.
private sub recursiveProcedure (wordApp as word.Application, child as
Task)
At the moment I have a standoff between having a button on the toolbar
and having these procedures inoperable or not using the toolbar or
menubar all because MS Project does not like a global declaration for
word.Application whereas Excel.Application works just fine.
I wonder if anyone has every experienced what I'm experiencing here?
Thanks and regards
Michael A.