G
Gary Shell
I have created a macro to isolate a specific set of tasks in a Project Gant
Chart view. I want to add a button of some sort to the project file to
execute this macro. Of course I can do this using a custom toolbar. Trouble
is that adds the toolbar to the Global.mpt and consequently EVERY Project
file I open has the toolbar. I don't want this. I want to add a button
to just ONE Project file.
This project file is actually being created by a VB.NET application which
instantiates MS Project, creates all the tasks with predecessor info and
then using this bit of code, it adds my macro to the instantiated Project
file:
----------
'point to this assembly
Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
'get the macro text from the resources
Dim ResourceStream As System.IO.Stream =
thisExe.GetManifestResourceStream("MSProjectExport.TraceMacro.txt")
'load the stream into a stream reader
Dim ResourceStreamReader As System.IO.StreamReader = New
System.IO.StreamReader(ResourceStream)
'get the text into a string
Dim theMacroText As String = ResourceStreamReader.ReadToEnd
Dim theVBProject As Microsoft.Vbe.Interop.VBProject
For Each theVBProject In ProjectApp.VBE.VBProjects
'note that we need to point to the LAST VBProject, the first one is the
'Global Project and would apply to all projects the user saves. We only
'want the macro to be instantiated on this particular project file which
'would be the last one. This takes into account the fact that the user
'MIGHT have another Project file open.
Next
Dim theVBECodemodule As Microsoft.Vbe.Interop.CodeModule
'point to the code module in the MSProject file
theVBECodemodule = theVBProject.VBComponents.Item(1).CodeModule
'add the macro code to the project file
theVBECodemodule.AddFromString(theMacroText)
-----------
I then want to create SOME sort of button and add code to that button to
execute my macro. But once again I only want this button to appear in this
single Project file. I do NOT want it to be part of the Global Project
Template.
Am I dreaming, or can this be done.
I thought I might add some code to the OPEN event to create a custom toolbar
and other code to the BEFORE Close event to delete the custom tool bar, but
that seems like such a kludge.
Any ideas?
Gary Shell
Chart view. I want to add a button of some sort to the project file to
execute this macro. Of course I can do this using a custom toolbar. Trouble
is that adds the toolbar to the Global.mpt and consequently EVERY Project
file I open has the toolbar. I don't want this. I want to add a button
to just ONE Project file.
This project file is actually being created by a VB.NET application which
instantiates MS Project, creates all the tasks with predecessor info and
then using this bit of code, it adds my macro to the instantiated Project
file:
----------
'point to this assembly
Dim thisExe As System.Reflection.Assembly
thisExe = System.Reflection.Assembly.GetExecutingAssembly()
'get the macro text from the resources
Dim ResourceStream As System.IO.Stream =
thisExe.GetManifestResourceStream("MSProjectExport.TraceMacro.txt")
'load the stream into a stream reader
Dim ResourceStreamReader As System.IO.StreamReader = New
System.IO.StreamReader(ResourceStream)
'get the text into a string
Dim theMacroText As String = ResourceStreamReader.ReadToEnd
Dim theVBProject As Microsoft.Vbe.Interop.VBProject
For Each theVBProject In ProjectApp.VBE.VBProjects
'note that we need to point to the LAST VBProject, the first one is the
'Global Project and would apply to all projects the user saves. We only
'want the macro to be instantiated on this particular project file which
'would be the last one. This takes into account the fact that the user
'MIGHT have another Project file open.
Next
Dim theVBECodemodule As Microsoft.Vbe.Interop.CodeModule
'point to the code module in the MSProject file
theVBECodemodule = theVBProject.VBComponents.Item(1).CodeModule
'add the macro code to the project file
theVBECodemodule.AddFromString(theMacroText)
-----------
I then want to create SOME sort of button and add code to that button to
execute my macro. But once again I only want this button to appear in this
single Project file. I do NOT want it to be part of the Global Project
Template.
Am I dreaming, or can this be done.
I thought I might add some code to the OPEN event to create a custom toolbar
and other code to the BEFORE Close event to delete the custom tool bar, but
that seems like such a kludge.
Any ideas?
Gary Shell