如何以编程方式打开MS Project并运行VBA宏? [英] How to Programmatically open MS Project and run VBA macro?
问题描述
有没有办法可以通过代码打开MS Project客户端应用程序,稍后打开一个项目,运行保存在其中的宏然后发布所有这些行动都需要在后台完成。
问候
Agasthya
请注意,您需要一个非常好的错误处理:)
无论如何,可以这样做:
- 确保项目帐户(信息 - Project Web App Accounts)设置为"Use my default"帐户]在这台计算机上
- 确保在没有通知的情况下启用宏
创建一个仅包含VBA代码的项目(我称之为MacroProject),用于打开和修改所有必要的项目。 (所以我不修改"MacroProject",它只包含代码)。创建一个执行所有操作的过程。
示例,这将打开MyProject(不是MacroProject !!!!),发布并保存它:
Sub ModifyProjects()
FileOpenEx名称:="<> \ MyProject",ReadOnly:= False
'做一些
发布
FileCloseEx保存: = pjDoNotSave,CheckIn:= True
End SubIn" ThisProject(MacroProject)"输入例如下面的代码,用打开的操作调用你的宏:
Private Sub Project_Open(ByVal pj As Project)
Dim StopMacro
'给一些人一个编辑此代码的机会
如果Application.UserName =" Barbara Henhapl"或者Application.UserName<> "Contoso Administrator"然后
StopMacro = MsgBox("需要编辑宏?",vbYesNo)
如果StopMacro = vbYes则
退出Sub
结束如果
结束如果
'调用程序来完成工作
调用ModifyProjects
'关闭此宏项目而不保存
FileCloseEx保存:= pjDoNotSave,CheckIn:= True
'退出项目
Application.Quit
结束子
使用以下命令提示符启动整个过程(在系统中查找WinProj.exe的位置):
" C:\Program Files(x86)\ Microsoft Office \root \ Office 16 \ WINPROJ.EXE" "<> \MacroProject"
如果可行,请将此命令放在命令文件中,并使用任务计划程序定期运行它。
问候<
Barbara
Hi,
Is there any way using which I can open MS Project client side application via code, later open a project, run a macro saved in it and then publish and close the plan.
All these actions need to be done in background.
Regards
Agasthya
Hi,
note that you need a very good error handling :)
Anyway, it can be done:
- Ensure, that Project Account (Info - Project Web App Accounts) is set to "Use my default account" on this computer
- Ensure that Macros are enabeled without notificationCreate a project (I called it MacroProject) just containing VBA Code for opening and modifying all necessary projects. (So I don't modify the "MacroProject", it is just containing the code). Create a procedure for doing everything.
Sample, this will open MyProject (not MacroProject!!!!), Publish and save it:
Sub ModifyProjects() FileOpenEx Name:="<>\MyProject", ReadOnly:=False 'Do someting Publish FileCloseEx Save:=pjDoNotSave, CheckIn:=True End SubIn "ThisProject(MacroProject)" enter e.g. following code, to call your macro with actions on open:
Private Sub Project_Open(ByVal pj As Project) Dim StopMacro 'Give some People a chance to edit this code If Application.UserName = "Barbara Henhapl" Or Application.UserName <> "Contoso Administrator" Then StopMacro = MsgBox("Need to edit macro?", vbYesNo) If StopMacro = vbYes Then Exit Sub End If End If 'Call procedure to do the work Call ModifyProjects 'Close this MacroProject without saving FileCloseEx Save:=pjDoNotSave, CheckIn:=True 'Exit Project Application.Quit End SubStart the whole procedure with following command prompt (look for location of WinProj.exe on your system):
"C:\Program Files (x86)\Microsoft Office\root\Office16\WINPROJ.EXE" "<>\MacroProject"
If it works, put this command in a command-file and use Task Scheduler to run it regularily.
Regards
Barbara
这篇关于如何以编程方式打开MS Project并运行VBA宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!