我正在编写一个脚本,从excel内部生成一个MS项目计划。一切正常,但我在设置页眉和页脚时遇到问题。看起来我需要识别视图名称,但我经常遇到运行时错误1101或其他一些错误。
我正在研究丹麦版的MS-project(Side = Page,Sider = Pages),根据pagesetup菜单的标题,我的默认视图是“Gantt-diagram”。也尝试了“甘特图”没有运气。
Dim pjapp As Object
Dim newproj As Object
Set pjapp = CreateObject("MSProject.application")
pjapp.Visible = True
Set newproj = pjapp.Projects.Add
Set ActiveProject = newproj
' here I want to remove the legend (does not work)
pjapp.FilePageSetupLegendEx Name:="Gantt-diagram", LegendOn:=pjNoLegend
' here I want to set the footer
pjapp.FilePageSetupFooter Alignment:=pjRight
pjapp.FilePageSetupFooter Text:="&[Side] of &[Sider] just some text here"
' setting page to A3 format - this somehow works
pjapp.FilePageSetupPage PaperSize:=8
' here I want to setup the header (does not work)
pjapp.FilePageSetupHeader Name:="Gantt-diagram", Alignment:=pjRight, Text:="My header"
以下是一些尝试:
pjNoLegend
这样的内部常量会导致调试错误),因此将Project对象声明为其本机类型(例如Dim pjapp As MSProject.Application
)。FilePageSetupLegend
而不是FilePageSetupLegendEx
。FilePageSetupHeader
并跳过视图名称参数(它将默认为当前视图)。例如:pjapp.FilePageSetupFooter , pjRight, "&[Side] of &[Sider] just some text here"
ActiveProject
是MS Project中的保留字,所以在那里使用不同的变量名,或者只删除那行代码,因为你已经有了一个对象变量newproj,它已经是活动项目了。注意:要使用early binding(更简单),请包含对Microsoft Project对象库的引用。为此,在VB编辑器中,转到工具:引用并检查相应的引用(它可能被列为“Microsoft Office项目对象库”并将包含版本号 - 我使用的是2013年的v15.0 )。还要确保没有检查任何不正确的引用(例如,引用了错误的版本)。