VBA to Determine Whether Gannt or Network Diagram

K

KSwan

I have a small routine that I would like to do be able to detect
whether the current window is displaying a Gantt Chart or a Network
Diagram. I found a Screen property that if it is equal to
pjNetworkDiagram (3) I could possibly use but I cannot figure out how
to access it. The Screen property is a member of the View object.

Anybody ever do somethng like this?
 
G

Gary Phillips, PMP, SM&A Consulting

Hello KSwan.....

You're in luck! Yes, there is a way to do exactly what you want, and here
is the function I wrote to give me the screen type of all of the available
screens. You can do this in a single line of code within the function.

First, create a variable to receive the value returned by the function.
This function allows you to pass the name of any view to it, and if it's in
the project schedule, return the type of screen upon which the view is based.

"WhichView" is the name of the view you want to evaluate.

The following example sends the name of the currently displayed view to the
function, which then returns the type of screen to your variable.

************************************************************
'Define a variable to store the value returned by the function.

Dim sScreenType as string

'Call the vScreen function, send the name of the currently displayed view
to vScreen, and then store the "Screen Type" returned by vScreen in the
variable called sScreenType.

sScreenType = vScreen(ActiveProject.CurrentView)

Function vScreen(WhichView As String) As String

'pjviewscreen types =

'pjGantt '1
'pjNetworkDiagram '2
'pjRelationshipDiagram '3
'pjTaskForm '4
'pjTaskSheet '5
'pjResourceForm '6
'pjResourceSheet '7
'pjResourceGraph '8
'pjTaskDetailsForm '10
'pjTaskNameForm '11
'pjResourceNameForm '12
'pjCalendar '13
'pjTaskUsage '14
'pjResourceUsage '15


vScreen = Choose(ActiveProject.Views(WhichView).Screen, "Gantt", "Network",
"Relationship", "Task Form", _
"Task Sheet", "Resource Form", "Resource
Sheet", _
"Resource Graph", "", "Task Details",
"Task Name", _
"Resource Name", "Calendar", "Task Usage",
"Resource Usage")


Exit Function

End Function

************************************************************

How it works:

"ActiveProject.Views(WhichView).Screen" is the syntax that accesses the
"Screen" propery in the collection of views in the Active Project.
"WhichView" specifies which view within the collection of views from which to
read the Screen property.

The Screen value returned is the pjScreen constant = to one of the pj values
I listed above. The "Choose" operation selects a meaningful description of
the Screen Type from the list of choices I provided (that you can change to
anything you want).

Using this function, vScreen(ActiveProject.CurrentView) of a Gantt view
returns "Gantt". vScreen(ActiveProject.CurrentView) of a Network Diagram
returns "Network"

*************************************************************
Gary Phillips, PMP, SM&A Consulting. Real answers for real people.
 
K

Kevin Swan

Gary,
Thanks. I did get Rod's suggestion to work but yours did two things for me.
It gave me a reusable function and showed me how to access the Screen
property I found.
Thanks again.

"Gary Phillips, PMP, SM&A Consulting"
 

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