ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referencing Fields in MS Project (https://www.excelbanter.com/excel-programming/388144-referencing-fields-ms-project.html)

[email protected]

Referencing Fields in MS Project
 
I have a VB script in an Excel spreadsheet that imports data from a MS
Project file. Right now I have the Project fields that are being
imported hardcoded in the script, e.g. Name, Text1.

For Each task In MSProj.ActiveProject.Tasks
Cells(i,1) = task.Name
Cells(i,2) = task.Text1
i= i+ 1
Next t

I would like to be able to change which fields are being imported by
setting a value on a worksheet rather than having to change the code
each time. So if I wanted the Start and Finish fields for each task
rather than the Name and Text1 fields, I could change some cells from
"Name" and "Text1" to "Start" and "Finish". However, I'm not sure how
to change these strings into something that can reference the proper
field in the task object. Any suggestions.

Thanks.


Mike

Referencing Fields in MS Project
 
Dim MyField1 As String
Dim MyField2 As String

'Change A1 to the cell you have a field in
'Change B1 to the cell you have a field in
MyField1 = Range("A1").Value
MyField2 = Range("B1").Value

" wrote:

I have a VB script in an Excel spreadsheet that imports data from a MS
Project file. Right now I have the Project fields that are being
imported hardcoded in the script, e.g. Name, Text1.

For Each task In MSProj.ActiveProject.Tasks
Cells(i,1) = task.Name
Cells(i,2) = task.Text1
i= i+ 1
Next t

I would like to be able to change which fields are being imported by
setting a value on a worksheet rather than having to change the code
each time. So if I wanted the Start and Finish fields for each task
rather than the Name and Text1 fields, I could change some cells from
"Name" and "Text1" to "Start" and "Finish". However, I'm not sure how
to change these strings into something that can reference the proper
field in the task object. Any suggestions.

Thanks.



NickHK

Referencing Fields in MS Project
 
I don't use MS Project, but if the task has a Fields collection and you name
to 2 ranges that contain the field names, maybe something like this:

For Each task In MSProj.ActiveProject.Tasks
Cells(i,1) = task.Fields(Range("rngField1").Value)
Cells(i,2) = task.Fields(Range("rngField2").Value)
i= i+ 1
Next t

Also, I assume you have a line
Dim task as MSProject.Task

It may be better not to use the same word for a variable as is used as an
object. maybe:
Dim MyTask as MSProject.Task

NickHK

wrote in message
ups.com...
I have a VB script in an Excel spreadsheet that imports data from a MS
Project file. Right now I have the Project fields that are being
imported hardcoded in the script, e.g. Name, Text1.

For Each task In MSProj.ActiveProject.Tasks
Cells(i,1) = task.Name
Cells(i,2) = task.Text1
i= i+ 1
Next t

I would like to be able to change which fields are being imported by
setting a value on a worksheet rather than having to change the code
each time. So if I wanted the Start and Finish fields for each task
rather than the Name and Text1 fields, I could change some cells from
"Name" and "Text1" to "Start" and "Finish". However, I'm not sure how
to change these strings into something that can reference the proper
field in the task object. Any suggestions.

Thanks.





All times are GMT +1. The time now is 03:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com