Access FiledName in TaskUsage

R

RevKev

Hello All,

I am trying to access/get the fieldname of a column in a view. I can't seem
to figure it out. What I have is:
Dim curTable As Table
Set curTable = ActiveProject.TaskTables(ActiveProject.CurrentTable)
curTable.Apply

xlCol = curTable.TableFields.Item(0)

What I am trying to achieve is to allow the user to export a view to excel
and then programmatically build the view. What the Excel Sheet will need is
the headers / filed names.

Is there an easier way? Thanks for the help!
 
J

John

RevKev said:
Hello All,

I am trying to access/get the fieldname of a column in a view. I can't seem
to figure it out. What I have is:
Dim curTable As Table
Set curTable = ActiveProject.TaskTables(ActiveProject.CurrentTable)
curTable.Apply

xlCol = curTable.TableFields.Item(0)

What I am trying to achieve is to allow the user to export a view to excel
and then programmatically build the view. What the Excel Sheet will need is
the headers / filed names.

Is there an easier way? Thanks for the help!

RevKev,
It sounds like you are trying to develop a macro that is the same as, or
at least very similar to, one I developed a few months back (i.e.
replicate the current Project view in Excel). It took me a while to
figure out the part that's elusive to you, so rest assured that it isn't
something obvious or straightforward.

Here is a snippet of the code I used to get the fields used in current
view. There is a whole lot more to the complete macro but this should
get you started.

'first find out which fields are present in view
SelectBeginning
SelectRow
ColCount = ActiveSelection.FieldIDList.count
'get field IDs, friendly names, and column widths
NamFnd = False: RYGFnd = False: NoteFnd = False: FrstMsg = True
For i = 1 To ColCount
FldID(i) = ActiveSelection.FieldIDList(1)
ColNam(i) = FieldConstantToFieldName(ActiveSelection.FieldIDList(1))
If
activeproject.TaskTables(activeproject.CurrentTable).TableFields(i +
1).Title <> "" Then
ColNam(i) =
activeproject.TaskTables(activeproject.CurrentTable).TableFields(i +
1).Title
ElseIf CustomFieldGetName(ActiveSelection.FieldIDList(1)) <> "" Then
ColNam(i) = CustomFieldGetName(ActiveSelection.FieldIDList(1))
End If
SelectCellRight
Next i

Hope this helps.
John
Project MVP
 
R

Rod Gill

This is my code for reading the columns for the current View:

Sub test()
Dim fld As TableField
Dim flds As TableFields
Select Case ActiveProject.CurrentView
Case "Gantt Chart", "Task Sheet", "Task Usage"
Set flds =
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields
Case "Resource Sheet", "Resource Usage"
Set flds =
ActiveProject.ResourceTables(ActiveProject.CurrentTable).TableFields
Case Else
Debug.Print "No Table for this View", vbInformation + vbOKOnly
End Select
For Each fld In flds
Debug.Print FieldConstantToFieldName(fld.Field) 'Prints to
Immediate Window
Next fld
End Sub

--

Rod Gill
Microsoft MVP for Project

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

RevKev

Rod,
Thanks for your reply... My company just purchased 2 of your books. I
appreciate your help!

So, what I am trying to access is the fieldname in the column definition as
noted if you double click on the header of any given view.

If I am reading this code correctly, one would have to iterate through the
heirarchy narrowing down as to what view>table> that you are on and then
statically designate the values...

I have figured out how to export everything that I need to Excel, however,
the part I am missing is to be able to dynamically write these
header/fieldnames to an xlCol...
thanks for any help
 

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