Reputation: 148
I'm writing a Sub in Excel right now with VBA. I've successfully opened a MS Project project. Now, I want to add a new column in the MS Project file via Excel VBA. How do I do this?
'''vba
Dim MSProject As MSProject.Application
Dim project As MSProject.project
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = Sheets("Sheet1")
wb.Activate
ws.Select
' Open Microsoft Project project
Set MSProject = CreateObject("MSProject.Application")
With MSProject
.FileOpen "test.mpp"
.Application.Visible = True
End With
Set project = MSProject.ActiveProject
' Add column in Project (this syntax does not work)
MSProject.TableEditEx(Name:="test.mpp", TaskTable:=True, _NewFieldName:="JIRA Issue Key", Title:="JIRA Issue Key", Width:=15, _ShowInMenu:=True, _ColumnPosition:=1)
'''
Upvotes: 0
Views: 1587
Reputation: 8442
MSProject
as a variable name as it the name of the library. Same for project
. Typical variable names would be something like prjApp
and prj
.Name
argument in the TableEditEx
refers to the name of the table, not the project.TableApply
Here's how the code should look to add an existing field to the default table (Entry) in the default view (Gantt Chart):
prjApp.TableEditEx Name:="Entry", TaskTable:=True, NewFieldName:="Text1", Title:="Custom title here", Width:=15, ShowInMenu:=True, ColumnPosition:=1
prjApp.TableApply "Entry"
See the documentation for more information.
Upvotes: 1