Run a macro when creating a new project from a template

S

Susheel

Hello,
I'm trying to run a macro whenever a user creates a new project based on the
template I designed. But, I don't know what event is triggered when a new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even I
open the template, create a new project from the template and any subsequent
activation of the project saved from the template. This is understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since a
template object is opened but not a project object, above error message is
thrown.

So, my question is, what event handler should I call when a new project is
created from a template.

{MS Word application has something line AutoNew.. but I can't find anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks
 
J

John

Susheel said:
Hello,
I'm trying to run a macro whenever a user creates a new project based on the
template I designed. But, I don't know what event is triggered when a new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even I
open the template, create a new project from the template and any subsequent
activation of the project saved from the template. This is understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since a
template object is opened but not a project object, above error message is
thrown.

So, my question is, what event handler should I call when a new project is
created from a template.

{MS Word application has something line AutoNew.. but I can't find anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be quite
right. Just for reference, here is the code I use, and it is placed in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private." &
vbCr & _
"This file and the data it contains shall not be shared with" & vbCr
& _
"anyone outside of [your company name]. This includes all " & vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
S

Susheel

Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the template, as
you demonstrated. But, call to Application.FileProperties is throwing the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light on
this?

As you notice, my test case is a pretty generic one so could you please try
the same and see if it works for you?

Thanks
Susheel

John said:
Susheel said:
Hello,
I'm trying to run a macro whenever a user creates a new project based on the
template I designed. But, I don't know what event is triggered when a new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even I
open the template, create a new project from the template and any subsequent
activation of the project saved from the template. This is understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since a
template object is opened but not a project object, above error message is
thrown.

So, my question is, what event handler should I call when a new project is
created from a template.

{MS Word application has something line AutoNew.. but I can't find anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be quite
right. Just for reference, here is the code I use, and it is placed in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private." &
vbCr & _
"This file and the data it contains shall not be shared with" & vbCr
& _
"anyone outside of [your company name]. This includes all " & vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
S

Susheel

Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is created from
a template.

If I use Project_Open, File Properties is displayed every time a project is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly created
from a template?

Thanks

Susheel said:
Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the template, as
you demonstrated. But, call to Application.FileProperties is throwing the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light on
this?

As you notice, my test case is a pretty generic one so could you please try
the same and see if it works for you?

Thanks
Susheel

John said:
Susheel said:
Hello,
I'm trying to run a macro whenever a user creates a new project based on the
template I designed. But, I don't know what event is triggered when a new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even I
open the template, create a new project from the template and any subsequent
activation of the project saved from the template. This is understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since a
template object is opened but not a project object, above error message is
thrown.

So, my question is, what event handler should I call when a new project is
created from a template.

{MS Word application has something line AutoNew.. but I can't find anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be quite
right. Just for reference, here is the code I use, and it is placed in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private." &
vbCr & _
"This file and the data it contains shall not be shared with" & vbCr
& _
"anyone outside of [your company name]. This includes all " & vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
J

John

Susheel said:
Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is created from
a template.

If I use Project_Open, File Properties is displayed every time a project is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even the
DocumentProperty Object.

John
Project MVP
Susheel said:
Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the template, as
you demonstrated. But, call to Application.FileProperties is throwing the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light on
this?

As you notice, my test case is a pretty generic one so could you please try
the same and see if it works for you?

Thanks
Susheel

John said:
Hello,
I'm trying to run a macro whenever a user creates a new project based
on the
template I designed. But, I don't know what event is triggered when a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even
I
open the template, create a new project from the template and any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since
a
template object is opened but not a project object, above error message
is
thrown.

So, my question is, what event handler should I call when a new project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be quite
right. Just for reference, here is the code I use, and it is placed in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private." &
vbCr & _
"This file and the data it contains shall not be shared with" & vbCr
& _
"anyone outside of [your company name]. This includes all " & vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
S

Susheel

Hi John,
I'm glad I don't smoke :)

Here's my requirement:
I want to design a Project template that will require a user to enter
"Project Title" and "Manager" fields under "File -> Properties" dialog box
when the user creates a new project from the templete. {Only when a new
project is created}

So, the shortest and easiest way that I could think of is to run a macro
when a project is created from my template and have the macro display
FileProperties dialog. Granted this does not force the user to actually input
values for project title and manager fields but at least saves the user 2
mouse clicks.

There could be other ways to accomplish this for example customizing the
Project Guide to accept user input for these project properties. But I don't
know how to do that.

So, lets stick with my easy way.

When I create a project from the template which has a call to Project_Open
and a method to show file properties, the FileProperties dialog is displayed
with out any problem.

But, it seems like this piece of code is saved into the actual project
itself (.mpp) and FileProperties dialog is displayed whenever the mpp file is
opened. I do not want that. FileProperties should be displayed only during
the mpp creation time and not during subsequent access to the mpp file. In
other words, this code must be executed only in the template (.mpt) and not
in the project file (.mpp).

I hope this is clear. Can you kindly help me with this?

Thanks
Susheel

John said:
Susheel said:
Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is created from
a template.

If I use Project_Open, File Properties is displayed every time a project is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even the
DocumentProperty Object.

John
Project MVP
Susheel said:
Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the template, as
you demonstrated. But, call to Application.FileProperties is throwing the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light on
this?

As you notice, my test case is a pretty generic one so could you please try
the same and see if it works for you?

Thanks
Susheel

:

Hello,
I'm trying to run a macro whenever a user creates a new project based
on the
template I designed. But, I don't know what event is triggered when a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when even
I
open the template, create a new project from the template and any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error message
saying that "Method is not available in this situation". I think since
a
template object is opened but not a project object, above error message
is
thrown.

So, my question is, what event handler should I call when a new project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be quite
right. Just for reference, here is the code I use, and it is placed in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private." &
vbCr & _
"This file and the data it contains shall not be shared with" & vbCr
& _
"anyone outside of [your company name]. This includes all " & vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
J

John

Susheel said:
Hi John,
I'm glad I don't smoke :)

Here's my requirement:
I want to design a Project template that will require a user to enter
"Project Title" and "Manager" fields under "File -> Properties" dialog box
when the user creates a new project from the templete. {Only when a new
project is created}

So, the shortest and easiest way that I could think of is to run a macro
when a project is created from my template and have the macro display
FileProperties dialog. Granted this does not force the user to actually input
values for project title and manager fields but at least saves the user 2
mouse clicks.

There could be other ways to accomplish this for example customizing the
Project Guide to accept user input for these project properties. But I don't
know how to do that.

So, lets stick with my easy way.

When I create a project from the template which has a call to Project_Open
and a method to show file properties, the FileProperties dialog is displayed
with out any problem.

But, it seems like this piece of code is saved into the actual project
itself (.mpp) and FileProperties dialog is displayed whenever the mpp file is
opened. I do not want that. FileProperties should be displayed only during
the mpp creation time and not during subsequent access to the mpp file. In
other words, this code must be executed only in the template (.mpt) and not
in the project file (.mpp).

I hope this is clear. Can you kindly help me with this?

Thanks
Susheel
Susheel,
OK, try this. Include code in the Open Event macro that tests for a
value in say, the "Manager" field. If there is an entry, then don't
display FileProperties. That should give you what you want. The macro
will run every time the file is open but it will only display the file
properties when a actual input is required (i.e. bug the user until they
comply - heh, heh).

The following code will do what I just described. Note: the "manager"
property is index item 20. You can see the complete list of available
properties by looking at the DocumentProperty Object in the Object
Bowser. Keep in mind that not all properties apply to Project files.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If ActiveProject.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
End If
End Sub

Hope this helps.
John
Project MVP
John said:
Susheel said:
Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since
beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is created
from
a template.

If I use Project_Open, File Properties is displayed every time a project
is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly
created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even the
DocumentProperty Object.

John
Project MVP
:

Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the
template, as
you demonstrated. But, call to Application.FileProperties is throwing
the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not
the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light
on
this?

As you notice, my test case is a pretty generic one so could you please
try
the same and see if it works for you?

Thanks
Susheel

:

Hello,
I'm trying to run a macro whenever a user creates a new project
based
on the
template I designed. But, I don't know what event is triggered when
a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template
VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when
even
I
open the template, create a new project from the template and any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error
message
saying that "Method is not available in this situation". I think
since
a
template object is opened but not a project object, above error
message
is
thrown.

So, my question is, what event handler should I call when a new
project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran
a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be
quite
right. Just for reference, here is the code I use, and it is placed
in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private."
&
vbCr & _
"This file and the data it contains shall not be shared with" &
vbCr
& _
"anyone outside of [your company name]. This includes all " &
vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
S

Susheel

Hi John,
I tried your code with following changes and the good news is that the code
worked perfectlyas expected in a .mpp file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If pj.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
Else
MsgBox "Project Manager is set to " + pj.BuiltinDocumentProperties(20)
End If
End Sub

But, if I place the same code in a .mpt (template) file and either open the
template or create an new project from the template, I get an error saying
that "Method is not available in this situation". Debugger highlights
"Application.FileProperties"

So I guess the context in which Application object is called with in the
template is incorrect.

I'm new to VBA and hence could not figure out the right context for the
objects & methods I'm referring to.

Any futher help on this is greatly appreciated.

Thanks

John said:
Susheel said:
Hi John,
I'm glad I don't smoke :)

Here's my requirement:
I want to design a Project template that will require a user to enter
"Project Title" and "Manager" fields under "File -> Properties" dialog box
when the user creates a new project from the templete. {Only when a new
project is created}

So, the shortest and easiest way that I could think of is to run a macro
when a project is created from my template and have the macro display
FileProperties dialog. Granted this does not force the user to actually input
values for project title and manager fields but at least saves the user 2
mouse clicks.

There could be other ways to accomplish this for example customizing the
Project Guide to accept user input for these project properties. But I don't
know how to do that.

So, lets stick with my easy way.

When I create a project from the template which has a call to Project_Open
and a method to show file properties, the FileProperties dialog is displayed
with out any problem.

But, it seems like this piece of code is saved into the actual project
itself (.mpp) and FileProperties dialog is displayed whenever the mpp file is
opened. I do not want that. FileProperties should be displayed only during
the mpp creation time and not during subsequent access to the mpp file. In
other words, this code must be executed only in the template (.mpt) and not
in the project file (.mpp).

I hope this is clear. Can you kindly help me with this?

Thanks
Susheel
Susheel,
OK, try this. Include code in the Open Event macro that tests for a
value in say, the "Manager" field. If there is an entry, then don't
display FileProperties. That should give you what you want. The macro
will run every time the file is open but it will only display the file
properties when a actual input is required (i.e. bug the user until they
comply - heh, heh).

The following code will do what I just described. Note: the "manager"
property is index item 20. You can see the complete list of available
properties by looking at the DocumentProperty Object in the Object
Bowser. Keep in mind that not all properties apply to Project files.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If ActiveProject.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
End If
End Sub

Hope this helps.
John
Project MVP
John said:
Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since
beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is created
from
a template.

If I use Project_Open, File Properties is displayed every time a project
is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly
created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even the
DocumentProperty Object.

John
Project MVP

:

Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the
template, as
you demonstrated. But, call to Application.FileProperties is throwing
the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is not
the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some light
on
this?

As you notice, my test case is a pretty generic one so could you please
try
the same and see if it works for you?

Thanks
Susheel

:

Hello,
I'm trying to run a macro whenever a user creates a new project
based
on the
template I designed. But, I don't know what event is triggered when
a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template
VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up when
even
I
open the template, create a new project from the template and any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error
message
saying that "Method is not available in this situation". I think
since
a
template object is opened but not a project object, above error
message
is
thrown.

So, my question is, what event handler should I call when a new
project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just ran
a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be
quite
right. Just for reference, here is the code I use, and it is placed
in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company private."
&
vbCr & _
"This file and the data it contains shall not be shared with" &
vbCr
& _
"anyone outside of [your company name]. This includes all " &
vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
J

John

Susheel said:
Hi John,
I tried your code with following changes and the good news is that the code
worked perfectlyas expected in a .mpp file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If pj.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
Else
MsgBox "Project Manager is set to " +
pj.BuiltinDocumentProperties(20)
End If
End Sub

But, if I place the same code in a .mpt (template) file and either open the
template or create an new project from the template, I get an error saying
that "Method is not available in this situation". Debugger highlights
"Application.FileProperties"

So I guess the context in which Application object is called with in the
template is incorrect.

I'm new to VBA and hence could not figure out the right context for the
objects & methods I'm referring to.

Any futher help on this is greatly appreciated.

Thanks

Susheel,
I copied your code to my test template file. It runs fine so there is
nothing wrong with your syntax. I think the problem might be with your
object library references. Do the following,
1. Open the VB Editor
2. Go to Tools/References
3. You should have the following references checked
Visual Basic For Applications
Microsoft Project 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library

If one or more of those references is NOT checked, then locate it in the
list and check it. The try your code on your template file again.

John
Project MVP
John said:
Susheel said:
Hi John,
I'm glad I don't smoke :)

Here's my requirement:
I want to design a Project template that will require a user to enter
"Project Title" and "Manager" fields under "File -> Properties" dialog
box
when the user creates a new project from the templete. {Only when a new
project is created}

So, the shortest and easiest way that I could think of is to run a macro
when a project is created from my template and have the macro display
FileProperties dialog. Granted this does not force the user to actually
input
values for project title and manager fields but at least saves the user 2
mouse clicks.

There could be other ways to accomplish this for example customizing the
Project Guide to accept user input for these project properties. But I
don't
know how to do that.

So, lets stick with my easy way.

When I create a project from the template which has a call to
Project_Open
and a method to show file properties, the FileProperties dialog is
displayed
with out any problem.

But, it seems like this piece of code is saved into the actual project
itself (.mpp) and FileProperties dialog is displayed whenever the mpp
file is
opened. I do not want that. FileProperties should be displayed only
during
the mpp creation time and not during subsequent access to the mpp file.
In
other words, this code must be executed only in the template (.mpt) and
not
in the project file (.mpp).

I hope this is clear. Can you kindly help me with this?

Thanks
Susheel
Susheel,
OK, try this. Include code in the Open Event macro that tests for a
value in say, the "Manager" field. If there is an entry, then don't
display FileProperties. That should give you what you want. The macro
will run every time the file is open but it will only display the file
properties when a actual input is required (i.e. bug the user until they
comply - heh, heh).

The following code will do what I just described. Note: the "manager"
property is index item 20. You can see the complete list of available
properties by looking at the DocumentProperty Object in the Object
Bowser. Keep in mind that not all properties apply to Project files.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If ActiveProject.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
End If
End Sub

Hope this helps.
John
Project MVP
:

Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since
beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is
created
from
a template.

If I use Project_Open, File Properties is displayed every time a
project
is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly
created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what
exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they
be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even
the
DocumentProperty Object.

John
Project MVP

:

Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the
template, as
you demonstrated. But, call to Application.FileProperties is
throwing
the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is
not
the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some
light
on
this?

As you notice, my test case is a pretty generic one so could you
please
try
the same and see if it works for you?

Thanks
Susheel

:

Hello,
I'm trying to run a macro whenever a user creates a new project
based
on the
template I designed. But, I don't know what event is triggered
when
a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template
VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up
when
even
I
open the template, create a new project from the template and
any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error
message
saying that "Method is not available in this situation". I
think
since
a
template object is opened but not a project object, above error
message
is
thrown.

So, my question is, what event handler should I call when a new
project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't
find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows
XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just
ran
a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be
quite
right. Just for reference, here is the code I use, and it is
placed
in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company
private."
&
vbCr & _
"This file and the data it contains shall not be shared with"
&
vbCr
& _
"anyone outside of [your company name]. This includes all " &
vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 
S

Susheel

Hi John,
Your solution worked perfectly. I didn't have to make any changes to the
references.

Thanks a bunch for all your help. In fact, I used your solution to build a
user form and update builtindocumentproperties...

Thanks a lot
Susheel

John said:
Susheel said:
Hi John,
I tried your code with following changes and the good news is that the code
worked perfectlyas expected in a .mpp file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If pj.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
Else
MsgBox "Project Manager is set to " +
pj.BuiltinDocumentProperties(20)
End If
End Sub

But, if I place the same code in a .mpt (template) file and either open the
template or create an new project from the template, I get an error saying
that "Method is not available in this situation". Debugger highlights
"Application.FileProperties"

So I guess the context in which Application object is called with in the
template is incorrect.

I'm new to VBA and hence could not figure out the right context for the
objects & methods I'm referring to.

Any futher help on this is greatly appreciated.

Thanks

Susheel,
I copied your code to my test template file. It runs fine so there is
nothing wrong with your syntax. I think the problem might be with your
object library references. Do the following,
1. Open the VB Editor
2. Go to Tools/References
3. You should have the following references checked
Visual Basic For Applications
Microsoft Project 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library

If one or more of those references is NOT checked, then locate it in the
list and check it. The try your code on your template file again.

John
Project MVP
John said:
Hi John,
I'm glad I don't smoke :)

Here's my requirement:
I want to design a Project template that will require a user to enter
"Project Title" and "Manager" fields under "File -> Properties" dialog
box
when the user creates a new project from the templete. {Only when a new
project is created}

So, the shortest and easiest way that I could think of is to run a macro
when a project is created from my template and have the macro display
FileProperties dialog. Granted this does not force the user to actually
input
values for project title and manager fields but at least saves the user 2
mouse clicks.

There could be other ways to accomplish this for example customizing the
Project Guide to accept user input for these project properties. But I
don't
know how to do that.

So, lets stick with my easy way.

When I create a project from the template which has a call to
Project_Open
and a method to show file properties, the FileProperties dialog is
displayed
with out any problem.

But, it seems like this piece of code is saved into the actual project
itself (.mpp) and FileProperties dialog is displayed whenever the mpp
file is
opened. I do not want that. FileProperties should be displayed only
during
the mpp creation time and not during subsequent access to the mpp file.
In
other words, this code must be executed only in the template (.mpt) and
not
in the project file (.mpp).

I hope this is clear. Can you kindly help me with this?

Thanks
Susheel
Susheel,
OK, try this. Include code in the Open Event macro that tests for a
value in say, the "Manager" field. If there is an entry, then don't
display FileProperties. That should give you what you want. The macro
will run every time the file is open but it will only display the file
properties when a actual input is required (i.e. bug the user until they
comply - heh, heh).

The following code will do what I just described. Note: the "manager"
property is index item 20. You can see the complete list of available
properties by looking at the DocumentProperty Object in the Object
Bowser. Keep in mind that not all properties apply to Project files.

Private Sub Project_Open(ByVal pj As MSProject.Project)
If ActiveProject.BuiltinDocumentProperties(20) = "" Then
Application.FileProperties
End If
End Sub

Hope this helps.
John
Project MVP

:

Oh... I don't know what I have been smoking... but I realized that
Project_Open also works... and it has been working for me since
beginning.

My real requirement is that, this piece of code that displays File
Properties dialog should only be executed when a new project is
created
from
a template.

If I use Project_Open, File Properties is displayed every time a
project
is
opened. I do not want that.
I sincerely apologize for confusing you and myself :)

So, is there any way to trigger a macro only when a project is newly
created
from a template?

Thanks

Susheel,
Warning, the Surgeon General has stated, smoking .....

Well I am confused. What exactly do you want to happen? And what
exactly
do you mean by, "..trigger a macro only when a project is newly created
from a template"? From my viewpoint, as soon as a user opens a template
they are effectively creating a new project. Otherwise why would they
be
opening the template, unless it is just to see what it looks like?

What exactly are you trying to accomplish with the FIleProperties
Method? Maybe what you really want to access is the
BuiltinDocumentProperties, CustomDocumentProperties, or perhaps even
the
DocumentProperty Object.

John
Project MVP

:

Hi John,
Thank you for the prompt response. It is much appreciated.
I should've mentioned this initially.. but here it is anyway...
I was able to trigger Project_Open with a MsgBox call from the
template, as
you demonstrated. But, call to Application.FileProperties is
throwing
the
following error.

"Method is not available in this situation".

It seems like the context in which I'm calling FileProperties is
not
the
right one. Maybe I should use something other than
MSProject.Application.FileProperties... Can you kindly throw some
light
on
this?

As you notice, my test case is a pretty generic one so could you
please
try
the same and see if it works for you?

Thanks
Susheel

:

Hello,
I'm trying to run a macro whenever a user creates a new project
based
on the
template I designed. But, I don't know what event is triggered
when
a
new
project is created from a template.
Code:

Private Sub Project_Activate(ByVal pj As MSProject.Project)
pj.Application.FileProperties
End Sub

Above code is placed under "ThisProject" under my template
VBAProject.

Now, the problem is...
When I use Project_Activate, File Properties dialog shows up
when
even
I
open the template, create a new project from the template and
any
subsequent
activation of the project saved from the template. This is
understandable as
Project_Activate is meant for that.

When I use Project_Open in the template, I get a runtime error
message
saying that "Method is not available in this situation". I
think
since
a
template object is opened but not a project object, above error
message
is
thrown.

So, my question is, what event handler should I call when a new
project
is
created from a template.

{MS Word application has something line AutoNew.. but I can't
find
anything
similar to that in MS Project}

BTW, I'm using MS Project 2003 Professional edition on Windows
XP
Professional.

Thanks

Susheel,
It shouldn't matter whether the file is a template or not. I just
ran
a
quick test on a template file that has an Open Event macro and
everything worked fine. I suspect your Open Event code may not be
quite
right. Just for reference, here is the code I use, and it is
placed
in
the "ThisPoject" folder of the template file.

Private Sub Project_Open(ByVal pj As MSProject.Project)
MsgBox "WARNING - the data you are about to view is company
private."
&
vbCr & _
"This file and the data it contains shall not be shared with"
&
vbCr
& _
"anyone outside of [your company name]. This includes all " &
vbCr &
vbCr & _
"customers, suppliers, individuals or corporate entities.",
vbCritical, "SECURITY WARNING"
End Sub

Hope this helps.
John
Project MVP
 

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