Run code before an event

D

DavidC

Hi,

I have a simple task that seems to fit with a small VBA routine.

In essence I want to have a revision number in the header. The easy way is
to simply add the number into the header in 'pagesetup'. However that
requires a conscious descision to set that number up. In practice (for me)
it is a case of updating a project often to answer a management query or for
a meeting and printing the schedule out, and I tend to simply hit the print
button (laziness I know, but it is reality).

What I would like to do is to assign a custom field under properties that
reflects the revision number and that can be used in the page header. From
what I can see the standard pick list does not include those custom fields
setup in the file properties, nor does it include the 'revision' field which
is part of the builtin properties. Setting a routine to update the revision
number and checking to see if in fact the print is a revision is sorted, but
I am struggling to find the code that runs when I click on the 'print
button'. I was hoping that when clicking on the print button, the code would
run, update the revision (if necessary) and reflect that number into the
header/footer, then proceed to the normal dialog box for printing.

any thoughts would be appreciated.

Regards

DavidC
 
J

Jan De Messemaeker

Hi,

You can use a custom field like say Text22 on the Project Summary Task.
That can appear in the header.
And in the ThisProject Object of the file you can have a Project_BeforePrint
procedure
Visual Basic EditorIn the Project Explorer, Double-Click o,n "Microsoft
Project Objects" in the file
Double-Click "ThisProject"
In the code window, left select project, Right Before Print.

Hope this helps
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availabliy check:
http://users.online.be/prom-ade/Calendar.pdf
 
D

DavidC

Hi Jan,

Thanks for your response.

The code I have tried is below. The code to set the revision etc works
fine, it is that portion which starts the code when the print button is
selected. From what have read and seen it seems that the
"ProjectbeforePrint" is the command and it needs to be in a class module, but
when I select print, all that happens is that the view prints without the
prompt in my code appearing. I am certain it is a stupid little thing I am
missing, but I seem to be missing it.

Any thoughts??

Public WithEvents projapp As MSProject.Application


Private Sub projapp_ProjectBeforePrint(ByVal pj As MSProject.Project, cancel
As Boolean)

Dim mydoc As String, myrev As Double, myanswer As String

Set myproj = ActiveProject

myrev = myproj.BuiltinDocumentProperties(8)

myanswer = MsgBox("Is this a new revision?", vbYesNo)

If myanswer = False Then


Else

myrev = myrev + 1

myproj.BuiltinDocumentProperties(8) = myrev

myproj.CustomDocumentProperties(8) = myrev

End If

FilePageSetupFooter Alignment:=pjLeft, Text:="&[File] - " & myrev


End Sub

Regards

DavidC
 
J

Jan De Messemaeker

Hi,

I so rarely have to ues these application events that it would take me quite
some time to look this up in Rod Gill's book.
Have you tried my suggestion to use the Project event?

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availabliy check:
http://users.online.be/prom-ade/Calendar.pdf
DavidC said:
Hi Jan,

Thanks for your response.

The code I have tried is below. The code to set the revision etc works
fine, it is that portion which starts the code when the print button is
selected. From what have read and seen it seems that the
"ProjectbeforePrint" is the command and it needs to be in a class module,
but
when I select print, all that happens is that the view prints without the
prompt in my code appearing. I am certain it is a stupid little thing I
am
missing, but I seem to be missing it.

Any thoughts??

Public WithEvents projapp As MSProject.Application


Private Sub projapp_ProjectBeforePrint(ByVal pj As MSProject.Project,
cancel
As Boolean)

Dim mydoc As String, myrev As Double, myanswer As String

Set myproj = ActiveProject

myrev = myproj.BuiltinDocumentProperties(8)

myanswer = MsgBox("Is this a new revision?", vbYesNo)

If myanswer = False Then


Else

myrev = myrev + 1

myproj.BuiltinDocumentProperties(8) = myrev

myproj.CustomDocumentProperties(8) = myrev

End If

FilePageSetupFooter Alignment:=pjLeft, Text:="&[File] - " & myrev


End Sub

Regards

DavidC

Jan De Messemaeker said:
Hi,

You can use a custom field like say Text22 on the Project Summary Task.
That can appear in the header.
And in the ThisProject Object of the file you can have a
Project_BeforePrint
procedure
Visual Basic EditorIn the Project Explorer, Double-Click o,n "Microsoft
Project Objects" in the file
Double-Click "ThisProject"
In the code window, left select project, Right Before Print.

Hope this helps
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availabliy check:
http://users.online.be/prom-ade/Calendar.pdf
 
D

DavidC

Hi Jan,

Yes I did try that with no luck. Seems that again I missed some minor
coding again. As with you it has been years now since I last did any coding
so am rusty to the extreme.

Thanks anyway for your help.

Regards

DavidC

Jan De Messemaeker said:
Hi,

I so rarely have to ues these application events that it would take me quite
some time to look this up in Rod Gill's book.
Have you tried my suggestion to use the Project event?

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availabliy check:
http://users.online.be/prom-ade/Calendar.pdf
DavidC said:
Hi Jan,

Thanks for your response.

The code I have tried is below. The code to set the revision etc works
fine, it is that portion which starts the code when the print button is
selected. From what have read and seen it seems that the
"ProjectbeforePrint" is the command and it needs to be in a class module,
but
when I select print, all that happens is that the view prints without the
prompt in my code appearing. I am certain it is a stupid little thing I
am
missing, but I seem to be missing it.

Any thoughts??

Public WithEvents projapp As MSProject.Application


Private Sub projapp_ProjectBeforePrint(ByVal pj As MSProject.Project,
cancel
As Boolean)

Dim mydoc As String, myrev As Double, myanswer As String

Set myproj = ActiveProject

myrev = myproj.BuiltinDocumentProperties(8)

myanswer = MsgBox("Is this a new revision?", vbYesNo)

If myanswer = False Then


Else

myrev = myrev + 1

myproj.BuiltinDocumentProperties(8) = myrev

myproj.CustomDocumentProperties(8) = myrev

End If

FilePageSetupFooter Alignment:=pjLeft, Text:="&[File] - " & myrev


End Sub

Regards

DavidC

Jan De Messemaeker said:
Hi,

You can use a custom field like say Text22 on the Project Summary Task.
That can appear in the header.
And in the ThisProject Object of the file you can have a
Project_BeforePrint
procedure
Visual Basic EditorIn the Project Explorer, Double-Click o,n "Microsoft
Project Objects" in the file
Double-Click "ThisProject"
In the code window, left select project, Right Before Print.

Hope this helps
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availabliy check:
http://users.online.be/prom-ade/Calendar.pdf
Hi,

I have a simple task that seems to fit with a small VBA routine.

In essence I want to have a revision number in the header. The easy
way
is
to simply add the number into the header in 'pagesetup'. However that
requires a conscious descision to set that number up. In practice (for
me)
it is a case of updating a project often to answer a management query
or
for
a meeting and printing the schedule out, and I tend to simply hit the
print
button (laziness I know, but it is reality).

What I would like to do is to assign a custom field under properties
that
reflects the revision number and that can be used in the page header.
From
what I can see the standard pick list does not include those custom
fields
setup in the file properties, nor does it include the 'revision' field
which
is part of the builtin properties. Setting a routine to update the
revision
number and checking to see if in fact the print is a revision is
sorted,
but
I am struggling to find the code that runs when I click on the 'print
button'. I was hoping that when clicking on the print button, the code
would
run, update the revision (if necessary) and reflect that number into
the
header/footer, then proceed to the normal dialog box for printing.

any thoughts would be appreciated.

Regards

DavidC
 

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