应用程序对象 (Project)
代表整个 Project 应用程序。 Application 对象包含:
Application-wide settings and options (many of the options in the Options dialog box on the Tools menu, for example).
可返回顶级对象(例如 ActiveCell 、 ActiveProject 等)的属性。
作用于应用程序范围的各元素的方法,例如视图、选定范围和编辑操作等。
Application 对象用法
使用 应用程序 属性返回项目中的 应用程序 对象。 下面的示例将 Windows 属性应用于 Application 对象。
Application.Windows("Project1.mpp").Activate
从其他应用程序使用 Project:晚期绑定
下面的示例在运行时创建 Microsoft Project 应用程序 对象、 创建新项目、 添加一个任务,保存项目,然后关闭该项目。 例如,复制并粘贴到 状态报告模块 CreateProject_Late宏在 Visual Basic 编辑器 (VBE) 的Word。
注意
[!注释] 因为应用程序只在运行时查询 MSProject.Application 类型库,Microsoft IntelliSense 不可用和性能相对较差,使用后期绑定。 脚本语言,如JavaScript和 VBScript,需要后期绑定。 VBScript 仅支持泛型 对象 和 变量 数据类型。 对于 VBA 和其他已编译的语言中有更好的性能,应使用早期绑定,通过设置对项目类型库的引用。
Sub CreateProject_Late()
Dim pjApp As Object
Set pjApp = CreateObject("MSProject.Application")
pjApp.Visible = True
pjApp.FileNew
pjApp.ActiveProject.Tasks.Add "Hang clocks"
pjApp.FileSaveAs "Clocks.mpp"
pjApp.FileClose
pjApp.Quit
End Sub
如果未将 Visible 属性设置为 True,Project 应用程序将在后台运行而不可见。
从其他应用程序使用 Project:早期绑定
早期绑定具有更好的性能,因为它在设计时加载的类型库。 若要使用早期绑定,必须设置项目应用程序从应用程序中使用的引用。 例如,在 VBE Word文档,在 工具菜单上单击 引用、 可用引用列表中滚动,然后选择 Microsoft 项目于 15.0 对象库复选框。
下面的示例打开一个项目,从另一个应用程序,如Excel 、 添加一个任务,然后保存并关闭项目。
Sub ModifyProject_Early()
Dim pjApp As MSProject.Application
Set pjApp = New MSProject.Application
pjApp.Visible = True
pjApp.FileOpen "Clocks.mpp"
pjApp.ActiveProject.Tasks.Add "Wind clocks"
pjApp.FileSave
pjApp.FileClose
pjApp.Quit
End Sub
备注
重要
对于应用程序级事件,请在设置 Application.Visible = True
后注册事件处理程序。
如果从其他应用程序实例化“项目”,并在将“应用程序”对象的“可见”属性设置为“True”之前注册了应用程序级别的事件,“应用程序”的子对象属性和方法将不起作用。 例如,Application.ActiveProject.Name
将无法访问。
许多属性和方法返回最常见的用户界面对象,例如活动项目 由 下拉菜单 属性表示 可以不使用 应用程序 对象识别符的情况下使用。 例如,而不是编写 Application.ActiveProject.Visible = True
可以编写 ActiveProject.Visible = True
事件
- AfterCubeBuilt
- ApplicationBeforeClose
- ConnectionStatusChanged
- IsFunctionalitySupported
- JobCompleted
- JobStart
- LoadWebPage
- LoadWebPane
- NewProject
- OnUndoOrRedo
- PaneActivate
- ProjectAfterSave
- ProjectAssignmentNew
- ProjectBeforeAssignmentChange
- ProjectBeforeAssignmentChange2
- ProjectBeforeAssignmentDelete
- ProjectBeforeAssignmentDelete2
- ProjectBeforeAssignmentNew
- ProjectBeforeAssignmentNew2
- ProjectBeforeClearBaseline
- ProjectBeforeClose
- ProjectBeforeClose2
- ProjectBeforePrint
- ProjectBeforePrint2
- ProjectBeforePublish
- ProjectBeforeResourceChange
- ProjectBeforeResourceChange2
- ProjectBeforeResourceDelete
- ProjectBeforeResourceDelete2
- ProjectBeforeResourceNew
- ProjectBeforeResourceNew2
- ProjectBeforeSave
- ProjectBeforeSave2
- ProjectBeforeSaveBaseline
- ProjectBeforeTaskChange
- ProjectBeforeTaskChange2
- ProjectBeforeTaskDelete
- ProjectBeforeTaskDelete2
- ProjectBeforeTaskNew
- ProjectBeforeTaskNew2
- ProjectCalculate
- ProjectResourceNew
- ProjectTaskNew
- SaveCompletedToServer
- SaveStartingToServer
- SecondaryViewChange
- WindowActivate
- WindowBeforeViewChange
- WindowDeactivate
- WindowGoalAreaChange
- WindowSelectionChange
- WindowSidepaneDisplayChange
- WindowSidepaneTaskChange
- WindowViewChange
- WorkpaneDisplayChange
方法
名称 |
---|
- About
- ActivateMicrosoftApp
- AddNewColumn
- AddProgressLine
- AddResourcesFromProjectServer
- AddSiteColumn
- AfterUnloadWebBrowserControl
- 警告
- AlignTableCellBottom
- AlignTableCellTop
- AlignTableCellVerticalCenter
- AppExecute
- ApplyReport
- ApplyReportLayoutTemplate
- AppMaximize
- AppMinimize
- AppMove
- AppRestore
- AppSize
- AutoCorrect
- AutoFilter
- AutoSaveToGlobal
- BarBoxFormat
- BarBoxStyles
- BarRounding
- BaseCalendarCreate
- BaseCalendarDelete
- BaseCalendarEditDays
- BaseCalendarRename
- BaseCalendarReset
- BaseCalendars
- BaselineClear
- BaselineSave
- BoxAlign
- BoxCellEdit
- BoxCellEditEx
- BoxCellLayout
- BoxDataTemplate
- BoxFormat
- BoxFormatEx
- BoxGetXPosition
- BoxGetYPosition
- BoxLayout
- BoxLayoutEx
- BoxLinkLabelsShow
- BoxLinks
- BoxLinksEx
- BoxLinkStyleToggle
- BoxProgressMarksShow
- BoxSet
- BoxShowHideFields
- BoxStylesEdit
- BoxStylesEditEx
- BoxZoom
- CacheSettings
- CacheStatus
- CalculateAll
- CalculateProject
- CalendarBarStyles
- CalendarBarStylesEdit
- CalendarBarStylesEditEx
- CalendarBestFitWeekHeight
- CalendarDateBoxes
- CalendarDateBoxesEx
- CalendarDateShading
- CalendarDateShadingEdit
- CalendarDateShadingEditEx
- CalendarLayout
- CalendarShowBarSplits
- CalendarTaskList
- CalendarTimescale
- CalendarWeekHeadingsEx
- ChangeColumnDataType
- ChangeStatusDate
- ChangeWorkingTimeEx
- CheckField
- CheckIn
- CheckOut
- CheckResourceErrors
- CheckTaskErrors
- CleanupCache
- CleanupProjectFromCache
- ClearConstraint
- CloseComparison
- CloseUndoTransaction
- ColumnAlignment
- ColumnBestFit
- ColumnDelete
- ColumnEdit
- ColumnInsert
- ComAddInsDialog
- CommitmentsPane
- CompareProjectsLegendToggle
- CompareProjectVersions
- ConsolidateProjects
- ConvertHangulToHanja
- CopyReport
- CreateComparisonReport
- CreateEnterpriseCalendar
- CreateProjectSite
- CustomFieldDelete
- CustomFieldGetFormula
- CustomFieldGetName
- CustomFieldIndicatorAdd
- CustomFieldIndicatorDelete
- CustomFieldIndicators
- CustomFieldMappingDialog
- CustomFieldPropertiesEx
- CustomFieldRename
- CustomFieldSetFormula
- CustomFieldValueList
- CustomFieldValueListAdd
- CustomFieldValueListDelete
- CustomFieldValueListGetItem
- CustomForms
- CustomizeField
- CustomizeIMEMode
- CustomOutlineCodeEditEx
- DateAdd
- DateDifference
- DateFormat
- DateSubtract
- DDEExecute
- DDEInitiate
- DDELinksUpdate
- DDEPasteLink
- DDETerminate
- DeleteFromDatabase
- DependenciesPane
- DetailsPaneToggle
- DetailStylesAdd
- DetailStylesFormat
- DetailStylesFormatEx
- DetailStylesProperties
- DetailStylesRemove
- DetailStylesRemoveAll
- DetailStylesToggleItem
- DisplaySharedWorkspace
- DistributeTableColumns
- DistributeTableRows
- DocClose
- DocMaximize
- DocMove
- DocRestore
- DocSize
- DocumentExport
- DocumentLibraryVersionsDialog
- DrawingCreate
- DrawingCycleColor
- DrawingMove
- DrawingProperties
- DrawingReshape
- DurationFormat
- DurationValue
- EditClear
- EditClearFormats
- EditClearHyperlink
- EditCopy
- EditCopyPicture
- EditCut
- EditDelete
- EditEnterpriseCalendar
- EditGoTo
- EditHyperlink
- EditInsert
- EditPaste
- EditPasteAsHyperlink
- EditPasteSpecial
- EditRedo
- EditTPStyle
- EditUndo
- EnterpriseGlobalCheckOut
- EnterpriseMakeServerURLTrusted
- EnterpriseProjectDelete
- EnterpriseProjectImportWizard
- EnterpriseProjectProfiles
- EnterpriseResourceGet
- EnterpriseResourcesImportEx
- EnterpriseResourcesOpen
- EnterpriseResSubstitutionWizard
- EnterpriseTeamBuilder
- FieldConstantToFieldName
- FieldNameToFieldConstant
- FileCloseAllEx
- FileCloseEx
- FileExit
- FileLoadLast
- FileNew
- FileOpenEx
- FileOpenOrCreate
- FileOpenUsingBackstage
- FilePageSetup
- FilePageSetupCalendar
- FilePageSetupCalendarText
- FilePageSetupCalendarTextEx
- FilePageSetupFooter
- FilePageSetupHeader
- FilePageSetupLegend
- FilePageSetupLegendEx
- FilePageSetupMargins
- FilePageSetupPage
- FilePageSetupView
- FilePrint
- FilePrintPreview
- FilePrintSetup
- FileProperties
- FileSave
- FileSaveAs
- FileSaveOffline
- FileSaveWorkspace
- FillAcross
- FillDown
- FilterApply
- FilterClear
- FilterEdit
- FilterNew
- Filters
- FilterShowSummaryRows
- 查找
- FindEx
- FindFile
- FindNext
- FindPrevious
- FollowHyperlink
- Font32Ex
- FontBold
- FontEx
- FontItalic
- FontStrikethrough
- FontUnderLine
- Form
- FormatCopy
- FormatPainter
- FormatPaste
- FormViewShow
- GanttBarEditEx
- GanttBarFormat
- GanttBarFormatEx
- GanttBarLinks
- GanttBarSize
- GanttBarStyleBaseline
- GanttBarStyleCritical
- GanttBarStyleDelete
- GanttBarStyleEdit
- GanttBarStyleLate
- GanttBarStyleSlack
- GanttBarStyleSlippage
- GanttBarTextDateFormat
- GanttChartWizard
- GanttRollup
- GanttShowBarSplits
- GanttShowDrawings
- GetCellInfo
- GetCurrentTheme
- GetProjectServerSettingsEx
- GetProjectServerVersion
- GetRedoListCount
- GetRedoListItem
- GetThemedColor
- GetUndoListCount
- GetUndoListItem
- GoalAreaChange
- GoalAreaHighlight
- GoalAreaTaskHighlight
- GoToItemInVersions
- GotoNextOverAllocation
- GotoTaskDates
- 网格线
- GridlinesEdit
- GridlinesEditEx
- GroupApply
- GroupBy
- GroupClear
- GroupMaintainHierarchy
- GroupNew
- 组
- HelpAbout
- HelpAnswerWizard
- HelpContents
- HelpLaunch
- HelpTechnicalSupport
- HighlightDrivenSuccessors
- HighlightDrivingPredecessors
- HighlightPredecessors
- HighlightSuccessors
- ImportCommitment
- ImportOutlookTasks
- InactivateTaskToggle
- InformationDialog
- InsertBlankRow
- InsertHyperlink
- InsertManualTask
- InsertMilestoneTask
- InsertNotes
- InsertResource
- InsertScheduledTask
- InsertSummaryTask
- InsertTask
- IsCommandEnabled
- IsOfficeTaskPaneVisible
- IsOffline
- IsReducedFunctionalityMode
- IsUndoingOrRedoing
- IsURLTrusted
- Layout
- LayoutNow
- LayoutRelatedNow
- LayoutSelectionNow
- LevelingClear
- LevelingOptions
- LevelingOptionsEx
- LevelNow
- LevelSelected
- LinksBetweenProjects
- LinkTasks
- LinkTasksEdit
- LinkToTaskList
- LoadWebBrowserControlEx
- LoadWebPaneControl
- LocaleID
- LookUpTableAddEx
- 宏
- MacroSecurity
- MacroShowCode
- MacroShowVba
- MailLogoff
- MailLogon
- MailPostDocument
- MailRoutingSlip
- MailSend
- MailSession
- MailSystem
- MakeFieldEnterprise
- MakeLocalCalendarEnterprise
- ManageSiteColumns
- MapEdit
- 消息
- NewTasksStartOn
- ObjectChangeIcon
- ObjectConvert
- ObjectInsert
- ObjectLinks
- ObjectVerb
- OfficeOnTheWeb
- OfficeTaskPaneHide
- OpenBrowser
- OpenFromSharePoint
- OpenServerPage
- OpenUndoTransaction
- OpenXML
- OptionsCalculation
- OptionsCalendar
- OptionsEditEx
- OptionsGeneralEx
- OptionsInterfaceEx
- OptionsSave
- OptionsSchedule
- OptionsSecurityEx
- OptionsSecurityTab
- OptionsSpelling
- OptionsViewEx
- Organizer
- OrganizerDeleteItem
- OrganizerMoveItem
- OrganizerRenameItem
- OutlineHideSubTasks
- OutlineIndent
- OutlineOutdent
- OutlineShowAllTasks
- OutlineShowSubTasks
- OutlineShowTasks
- OutlineSymbolsToggle
- PageBreakRemove
- PageBreakSet
- PageBreaksRemoveAll
- PageBreaksShow
- PaneClose
- PaneCreate
- PaneNext
- PanZoomPanTo
- PanZoomZoomTo
- PasteAsPicture
- PasteDestFormatting
- PasteSourceFormatting
- ProgressLines
- ProjectCheckOut
- ProjectMove
- ProjectStatistics
- ProjectSummaryInfo
- 发布
- Quit
- ReassignSelectedAssns
- RecurringTaskInsert
- 重做
- RegisterProject
- ReminderSet
- RemoveHighlight
- RenameReport
- Replace
- ReplaceEx
- ReportPrint
- ReportPrintPreview
- 报表
- ReportsDialog
- RequestProgressInformation
- RescheduleToNextAvailable
- ResetTPStyle
- ResourceActiveDirectory
- ResourceAddressBook
- ResourceAssignment
- ResourceAssignmentDialog
- ResourceCalendarEditDays
- ResourceCalendarReset
- ResourceCalendars
- ResourceComparison
- ResourceDetails
- ResourceGraphBarStyles
- ResourceGraphBarStylesEx
- ResourceMappingDialog
- ResourceSharing
- ResourceSharingPoolAction
- ResourceSharingPoolRefresh
- ResourceSharingPoolUpdate
- ResourceWindowsAccount
- RestoreSheetSelection
- RowClear
- RowDelete
- RowInsert
- Run
- SaveForSharing
- SaveSheetSelection
- SegmentBorderColor
- SegmentFillColor
- SelectAll
- SelectBeginning
- SelectCell
- SelectCellDown
- SelectCellLeft
- SelectCellRight
- SelectCellUp
- SelectColumn
- SelectEnd
- SelectionExtend
- SelectRange
- SelectResourceCell
- SelectResourceColumn
- SelectResourceField
- SelectRow
- SelectRowEnd
- SelectRowStart
- SelectSheet
- SelectTable
- SelectTaskAssns
- SelectTaskCell
- SelectTaskColumn
- SelectTaskField
- SelectTimescaleRange
- SelectToEnd
- SelectTPLineHeight
- SelectTPTask
- ServiceOptionsDialog
- SetActiveCell
- SetAutoFilter
- SetField
- SetLTRTable
- SetMatchingField
- SetResourceField
- SetResourceFieldByID
- SetRowHeight
- SetRTLTable
- SetShowTaskSuggestions
- SetShowTaskWarnings
- SetSidepaneStateButton
- SetSplitBar
- SetTaskField
- SetTaskFieldByID
- SetTaskMode
- SetTitleRowHeight
- SetTPField
- ShareProjectOnline
- ShowAddNewColumn
- ShowIgnoredTaskWarnings
- ShowOSFTaskPane
- ShowReportDataPane
- SidepaneTaskChange
- SidepaneToggle
- Sort
- SpellCheckField
- SpellingCheck
- SplitTask
- StopWebBrowserControlNavigation
- SummaryResourceAssignmentsRefresh
- SummaryTasksShow
- SynchronizeWithSite
- Table
- TableApply
- TableCopy
- TableEdit
- TableEditEx
- TableReset
- Tables
- TaskComparison
- TaskDeliverableCreate
- TaskDeliverableSync
- TaskDependencySync
- TaskDrivers
- TaskInspector
- TaskMove
- TaskMoveToStatusDate
- TaskOnTimeline
- TaskRespectLinks
- TextStyles32Ex
- TextStylesEx
- TimelineExport
- TimelineFormat
- TimelineGotoSelectedTask
- TimelineInsertTask
- TimelineShowHide
- TimelineTextOnBar
- TimelineViewToggle
- 时间刻度
- TimescaleEdit
- TimescaleNonWorking
- TimescaleNonWorkingEx
- ToggleAssignments
- ToggleChangeHighlighting
- TogglePreventResOveralloc
- ToggleResourceDetails
- ToggleTaskDetails
- ToggleTPAutoExpand
- ToggleTPResourceExpand
- ToggleTPUnassigned
- ToggleTPUnscheduled
- Undo
- UndoClear
- UnlinkTasks
- UnloadWebBrowserControl
- UpdateFromProjectServer
- UpdateProject
- UpdateTasks
- UsageViewEntryEx
- ViewApply
- ViewApplyEx
- ViewBar
- ViewCopy
- ViewEditCombination
- ViewEditSingle
- ViewReset
- 视图
- ViewsEx
- ViewShowCost
- ViewShowCumulativeCost
- ViewShowCumulativeWork
- ViewShowNotes
- ViewShowObjects
- ViewShowOverallocation
- ViewShowPeakUnits
- ViewShowPercentAllocation
- ViewShowPredecessorsSuccessors
- ViewShowRemainingAvailability
- ViewShowResourcesPredecessors
- ViewShowResourcesSuccessors
- ViewShowSchedule
- ViewShowUnitAvailability
- ViewShowWork
- ViewShowWorkAvailability
- VisualReports
- VisualReportsEdit
- VisualReportsNewTemplate
- VisualReportsSaveCube
- VisualReportsSaveDatabase
- VisualReportsView
- WBSCodeMaskEdit
- WBSCodeRenumber
- WebAddToFavorites
- WebCopyHyperlink
- WebGoBack
- WebGoForward
- WebHideToolbars
- WebOpenFavorites
- WebOpenHyperlink
- WebOpenSearchPage
- WebOpenStartPage
- WebRefresh
- WebSetSearchPage
- WebSetStartPage
- WebStopLoading
- WebToolbar
- WindowActivate
- WindowArrangeAll
- WindowHide
- WindowMoreWindows
- WindowNewWindow
- WindowNext
- WindowPrev
- WindowSplit
- WindowUnhide
- WorkOffline
- WrapText
- Zoom
- ZoomCalendar
- ZoomIn
- ZoomOut
- ZoomReport
- ZoomTimescale
- AddEngagement
- EngagementInfo
- GetDpiScaleFactor
- InsertTimelineBar
- 检查器
- LocaleName
- ProjectSummaryInfoEx
- RefreshEngagementsForProject
- RemoveTimelineBar
- SubmitAllEngagementsForProject
- SubmitSelectedEngagementsForProject
- TaskOnTimelineEx
- TimelineBarDateRange
- UpdateEngagementsForProject
属性
名称 |
---|
- ActiveCell
- ActiveProject
- ActiveSelection
- ActiveWindow
- AMText
- 应用程序
- AskToUpdateLinks
- Assistance
- AutoClearLeveling
- AutoLevel
- AutomaticallyFillPhoneticFields
- AutomationSecurity
- 内部版本
- Calculation
- Caption
- CellDragAndDrop
- COMAddIns
- CommandBars
- CompareProjectsCurrentVersionName
- CompareProjectsPreviousVersionName
- DateOrder
- DateSeparator
- DayLeadingZero
- DecimalSeparator
- DefaultAutoFilter
- DefaultDateFormat
- DefaultView
- DisplayAlerts
- DisplayEntryBar
- DisplayOLEIndicator
- DisplayPlanningWizard
- DisplayProjectGuide
- DisplayRecentFiles
- DisplayScheduleMessages
- DisplayScrollBars
- DisplayStatusBar
- DisplayViewBar
- DisplayWindowsInTaskbar
- DisplayWizardErrors
- DisplayWizardScheduling
- DisplayWizardUsage
- 版本
- EnableCancelKey
- EnableChangeHighlighting
- EnterpriseAllowLocalBaseCalendars
- EnterpriseListSeparator
- EnterpriseProtectActuals
- FileBuildID
- FileFormatID
- GetCacheStatusForProject
- GlobalBaseCalendars
- GlobalOutlineCodes
- GlobalReports
- GlobalResourceFilters
- GlobalResourceTables
- GlobalTaskFilters
- GlobalTaskTables
- GlobalViews
- GlobalViewsCombination
- GlobalViewsSingle
- Height
- IsCheckedOut
- Left
- LevelFreeformTasks
- LevelIndividualAssignments
- LevelingCanSplit
- LevelOrder
- LevelPeriodBasis
- LevelProposedBookings
- LevelWithinSlack
- ListSeparator
- LoadLastFile
- MonthLeadingZero
- MoveAfterReturn
- 名称
- NewTasksEstimated
- OperatingSystem
- PanZoomFinish
- PanZoomStart
- Parent
- Path
- PathSeparator
- PMText
- 配置文件
- 项目
- PromptForSummaryInfo
- RecentFilesMaximum
- ScreenUpdating
- ShowAssignmentUnitsAs
- ShowEstimatedDuration
- ShowWelcome
- StartWeekOn
- StartYearIn
- StatusBar
- SupportsMultipleDocuments
- SupportsMultipleWindows
- ThousandSeparator
- TimeLeadingZero
- TimescaleFinish
- TimescaleStart
- TimeSeparator
- Top
- TrustProjectServerAndWSSPages
- TwelveHourTimeFormat
- UndoLevels
- UsableHeight
- UsableWidth
- Use3DLook
- UseOMIDs
- UserControl
- UserName
- VBE
- Version
- Visible
- VisualReportsAdditionalTemplatePath
- VisualReportTemplateList
- Width
- Windows
- Windows2
- WindowState
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。