Task or Resource View?

J

JJ

Is there a way to tell programmatically if the user is in a Task View
versus a Resource View?
 
J

JJ

That will tell me the name of the current view, but I would have to
know all the names of the Task and Resource Views. Then I would have
to bounce the name of the Current View off the two lists to determine
if the view the user is in is a Task-related View or a Resource-
related View, right? What if there was a Task view that has the same
name as a Resource view?

If the user was in a Gantt Chart type view, then I would know that the
user is looking at Task data. If the user was on the Resource Usage
view, then I would know the user was looking at Resource data. Is
there are property that tells me which "side" I am on?
 
R

Rod Gill

So what is the macro trying to do? Can you apply specific Views so you know
what is active?

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



That will tell me the name of the current view, but I would have to
know all the names of the Task and Resource Views. Then I would have
to bounce the name of the Current View off the two lists to determine
if the view the user is in is a Task-related View or a Resource-
related View, right? What if there was a Task view that has the same
name as a Resource view?

If the user was in a Gantt Chart type view, then I would know that the
user is looking at Task data. If the user was on the Resource Usage
view, then I would know the user was looking at Resource data. Is
there are property that tells me which "side" I am on?
 
B

Bill B

JJ said:
Is there a way to tell programmatically if the user is in a Task View
versus a Resource View?

Try:

Function bIsTaskView(app as MSProject.Application) As Boolean
On Error Resume Next
Dim t As Task
Set t = app.ActiveCell.Task
bIsTaskView = Err = 0
Err.Clear
On Error GoTo 0
End Function
 
J

JJ

I am trying to clear out all of the Titles of each field in the
current table using the following code:

Set alltf = ActiveProject.TaskTables(strCurrTable).TableFields

For Each tf In alltf
tf.Title = ""
Next

However, I realized that the user might be in a Resource-related view
rather than a Task-related View. So that's why I am asking how I can
determine which type of view the user is currently in.

Thanks!
 
J

JJ

This function works GREAT! But I'm not sure I understand how it works
completely. I have a couple of questions.

1) Why do I have to pass the application into the function?
2) What does the line "bIsTaskView = Err = 0" do?

Thanks again!
JJ
 
B

Bill B

1) Why do I have to pass the application into the function?

You don't have to pass the application if you're doing it in VBA. I use VB6
which requires a declared instance of the MSProject.application object.

2) What does the line "bIsTaskView = Err = 0" do?

It's the same as:

if Err = 0 then
bIsTaskView = True
else
bIsTaskView = False
end if

If you're in a Resource view, trying to access ActiveCell.Task generates an
error, which sets the internal error object's value to some non-0 value. You
can display err.description if you're interested in what the error is.

Bill B
 

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