Matlab not accessing microsoft project applications

I am trying to access MS Project from Matlab to create a .mpp file and no matter what I try, I always get the same error:
Edit:
Undefined function or variable 'Projects'.
Error in Project_Testing (line 45) invoke(project.Projects,'Add');
I currently have the following code:
project = actxserver('MSProject.Application');
set(project,'Visible',1);
invoke(project.Projects,'Add');
invoke(project,'FileSaveAs','NewProject.mpp');
I am getting the error on project.Projects and I have also tried doing another invoke to get .Projects but nothing I have tried has worked

댓글 수: 3

That's not the full text of the error message. Please copy and paste the full message, all of the red text, into a comment on this Answer.
I don't have MS Projects installed on this machine, so can't test anything, but at first glance your code looks OK. Have you tried looking up the error code you get (and what is it anyway?)
Note that you don't need to use set and invoke, the following would work (or not work) just as well:
project = actxserver('MSProject.Application);
project.Visible = 1;
newproj = project.Projects.Add;
project.FileSaveAs('NewProject.mpp');
Note that for the last line, I'd use the SaveAs method of the project you've created instead:
newproj.SaveAs('NewProject.mpp');
using set and invoke were the only ways I could get anything to work without a similar error as above. Using your code, gave me a similar error as above but on the project.Visible = 1; line

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2017년 2월 7일
편집: Guillaume 2017년 2월 7일
After testing on a computer with MS project installed, it would appear that matlab does not 'see' the interface methods, properties, etc. so indeed you have to use get, set and invoke. Therefore, you can't use project.Projects, you have to get the Projects collection:
msproj = actxserver('MSProject.Application');
set(msproj, 'Visible', true);
projects = get(msproj, 'Projects');
newproj = invoke(projects, 'Add');
invoke(newproj, 'SaveAs', 'NewProject.mpp');
%...
invoke(msproj, 'Quit');
Maybe Steven Lord or somebody else from Mathworks will explain why matlab fails to see the interface properly ( methodsview only shows the standard matlab methods) yet still works with invoke.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

제품

질문:

2017년 2월 6일

편집:

2017년 2월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by