我现在正在使用VBA在Excel中编写Sub。我已经成功打开了一个MS Project项目。现在,我想通过Excel VBA在MS Project文件中添加新列。我该怎么做?
'''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)
'''
答案 0 :(得分:1)
MSProject
作为变量名,因为它是库名。与project
相同。典型的变量名可能类似于prjApp
和prj
。Name
中的TableEditEx
参数是指表的名称,而不是项目的名称。TableApply
这是在默认视图(甘特图)中将现有字段添加到默认表(条目)中的代码的外观:
prjApp.TableEditEx Name:="Entry", TaskTable:=True, NewFieldName:="Text1", Title:="Custom title here", Width:=15, ShowInMenu:=True, ColumnPosition:=1
prjApp.TableApply "Entry"
有关更多信息,请参见the documentation。