Toolbar Issue - Part Two

M

MichaelA

Following on from my other post regarding toolbars, I have found that
toolbars buttons created using VBA are always temporary. That is,
when I open a file, the project_open module executes creating the
toolbar and the associated buttons. Close the file and the toolbar
remains WITHOUT the buttons. Open the file and back they come. Also,
the toolbar automatically is loaded into the Global.MPT and not in the
local file.

Surely there must be a way to create a permanent toolbar such that
when other .mpp files are opened the toolbar doesn't have to be
recreated by having the addToolbar code in the Global.MPT!project_open
module?

Any ideas anyone?


Thanks and regards
Michael A.
 
J

Jack Dahlgren

I generally find the most reliable way to work with toolbars is to use the
organizer.
If you copy the toolbar into the Global.mpt - and the associated macros
which I presume that the toolbar buttons initiate - then you should have it
available for all projects. So typically, build in an individual file, then
use organizer to copy to global.mpt.

You can do that in code, or you could premake the toolbar and put it in an
otherwise empty project and have it copy over using VBA.

Since you are looking for a permanent toolbar, there is no need to create it
everytime.

-Jack Dahlgren
 
M

MichaelA

Jack,

Everything you say makes sense and that is in essence what I am trying
to do. When I open the template the toolbar is created and populated
with all the buttons. If I operate manually for a moment and take a
look in the organizer, I find that the new toolbar is already in the
Global.mpt file and not in the local .mpp file; hence there is nothing
to copy across. When the .mpp file is closed the toolbar remains
without any of the buttons.

I understand the need to copy across the module(s) that create the
toolbar; however there is a critical line that is in the ThisProject
(.mpp)!Project_Open module. It appears that there is no obvious way
to copy this line into the ThisProject(Global.MPT)!Project_Open module
which would allow the toolbar to be created everytime. Even though
the toolbar is permanent, the buttons aren't and there doesn't seem to
be a way to make them permanent hence the need to recreate everytime
MS Project is opened because I would like the toolbar to be available
for all .mpp files not just the template.

Any thoughts on this would be appreciated.

Thanks and regards
Michael Andersen
 
J

Jack Dahlgren

It sounds like the buttons are created in the project file, not in the global
file. If they are in the global file they will be persistant.

Try this.

Copy the toolbar using the organizer to a blank file.
Delete the toolbar from global.mpt
Remove your on open code.
Add the buttons you want (making sure they reference macros in the GLOBAL)
Save the project.
Close project (just in case)
Open project.
Open the file with the toolbar
copy the toolbar using the organizer into global.mpt
close the file
close project
Open project
What do you see?

-Jack Dahlgren
 
M

MichaelA

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.
 

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