Unable to Activate() a Project within the Application.Projects()

A

Activate()

Hi,

I am implmenting a custom .NET application with MSProject 2003 integration.

The integration is fine and the .NET app is also working fine. Now i am
stuck on the 'last lap'.

The application opens many .MPP files and updates them randomly (some are
modified and some are not). Now at the end of processing, i am having a
problem. I need to FileSave() only the modified ones. I know which ones.

Since only Application.ActiveProject can be FileSave(), as per MSDN
MSProject automation reference, we need to first activate 'The' project.
Refer my code below:

oMSProjectApp = CreateObject("MSProject.Application")

oMSProjectApp.FileOpen("c:\Project1.mpp") 'After this, Project1 is the
ActiveProject

oMSProjectApp.FileOpen("c:\Project2.mpp") 'After this, Project2 is the
ActiveProject

'I modify Project1..Now i need to save it..

oMSProjectApp.Projects(1).Activate()

This is throwing up an exception:

A first chance exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Run-time exception thrown : System.Runtime.InteropServices.COMException - An
unexpected error occurred with the method.

What is going wrong?!

Thanks in advance!
 
J

Jan De Messemaeker

Hi,

I have had this exception (through VBA, I do not use .NET) when trying to
activate the currently activeproject.
That is why I always use an On Error Resume Next before an activate
statement.

HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
D

DPJany

Hi Jan,

I confirmed that I am NOT trying to Activate() the currently ActiveProject.

Could you suggest further?

thanks!
 
R

Rod Gill

Hi,

Try:
Dim proj1 as MSProject.Project
Dim proj2 as MSProject.Project
proj1=oMSProjectApp.FileOpen("c:\Project1.mpp")
proj2=oMSProjectApp.FileOpen("c:\Project2.mpp")

'I modify Project1..Now i need to save it..

proj1.Activate()


--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

Author of the only book on Project VBA, see: http://www.projectvbabook.com




DPJany said:
Hi Jan,

I confirmed that I am NOT trying to Activate() the currently
ActiveProject.

Could you suggest further?

thanks!



__________ Information from ESET Smart Security, version of virus
signature database 4959 (20100319) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4959 (20100319) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
D

DPJany

Hi Rod,

I tried the following as suggested by you.

Dim proj1 As MSProject.Project
Dim proj2 As MSProject.Project
oMSProjectApp.FileOpen("c:\Inferno.mpp") 'Since this returns a
Bool
proj1 = oMSProjectApp.ActiveProject
oMSProjectApp.FileOpen("c:\Synergy.mpp")
proj2 = oMSProjectApp.ActiveProject

'I modify Project1..Now i need to save it..

proj1.Activate()

However, this is still throwing up on me. I have absolutely run out of clues
:-(

Kindly help.

Thanks!
-----------------------------
 
R

Rod Gill

There's no obvious reason why both versions shouldn't work. Both techniques
work in VBA so there must be a VSTO problem.

You have Project 2003, do you have SP3 applied?

What version of Visual Studio? It's fully updated? The project started off
as a Project 2003 VSTO app or you converted later?



--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

Author of the only book on Project VBA, see: http://www.projectvbabook.com




DPJany said:
Hi Rod,

I tried the following as suggested by you.

Dim proj1 As MSProject.Project
Dim proj2 As MSProject.Project
oMSProjectApp.FileOpen("c:\Inferno.mpp") 'Since this returns a
Bool
proj1 = oMSProjectApp.ActiveProject
oMSProjectApp.FileOpen("c:\Synergy.mpp")
proj2 = oMSProjectApp.ActiveProject

'I modify Project1..Now i need to save it..

proj1.Activate()

However, this is still throwing up on me. I have absolutely run out of
clues
:-(

Kindly help.

Thanks!
-----------------------------


__________ Information from ESET Smart Security, version of virus
signature database 4972 (20100324) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4972 (20100324) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 
D

DPJany

Hi Rod,

My apologies for this delayed response. Was caught up with some travel.

1. I have Project 2003 SP3 installed
2. I am using Visual Studio 2008 with all updates
3. I created the Project as a VB.NET Windows Forms Application
- New Project\Visual Basic\Windows\Windows Forms Application
- i am not using the New Project\Visual Basic\Office becos i am NOT
developing a Project 2003 Add-in

Any clues?!!!

Thanks.
-------------------
 
R

Rod Gill

Sorry,

I can't help any further. There are bugs in the Visual Studio Interface,
I've found 2 in VS2010 writing a Project 2010 add-in and that was in my
first (and fairly basic) add-in, so who knows what other bugs there are.

I think you may need to open and process on project at a time, or if you
need to save a project set projectsummarytask.flag1=true (set to false when
opening) then loop thru all open projects saving only those that have flag1
set. This avoids the need to activate.

--

Rod Gill
Microsoft MVP for Project - http://www.project-systems.co.nz

Author of the only book on Project VBA, see: http://www.projectvbabook.com




DPJany said:
Hi Rod,

My apologies for this delayed response. Was caught up with some travel.

1. I have Project 2003 SP3 installed
2. I am using Visual Studio 2008 with all updates
3. I created the Project as a VB.NET Windows Forms Application
- New Project\Visual Basic\Windows\Windows Forms Application
- i am not using the New Project\Visual Basic\Office becos i am NOT
developing a Project 2003 Add-in

Any clues?!!!

Thanks.
-------------------


__________ Information from ESET Smart Security, version of virus
signature database 5070 (20100428) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 5070 (20100428) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top