如何从Excel VBA在Microsoft Project中添加新列? [英] How to add a new column in Microsoft Project from Excel VBA?

查看:86
本文介绍了如何从Excel VBA在Microsoft Project中添加新列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用VBA在Excel中编写Sub.我已经成功打开了一个MS Project项目.现在,我想通过Excel VBA在MS Project文件中添加一个新列.我该怎么做?

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)

'''

推荐答案

  1. 请勿使用 MSProject 作为变量名,因为它是库的名称.与 project 相同.典型的变量名可能类似于 prjApp prj .
  2. 您是否有一个名为"JIRA发行密钥"的企业字段?字段名称必须是有效的现有字段.
  3. TableEditEx 中的 Name 参数是指表的名称,而不是项目的名称.
  4. 编辑表格后,您需要使用 TableApply
  5. 应用更改
  1. Don't use 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.
  2. Do you have an enterprise field named "JIRA Issue Key"? The field name must be a valid, existing field.
  3. The Name argument in the TableEditEx refers to the name of the table, not the project.
  4. After editing the table, you need to apply changes with 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.

这篇关于如何从Excel VBA在Microsoft Project中添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆