Inserting object in MS Project file (.mpp) with C#

A

Anindya P

Hi,
I am trying to insert a xml configuration file as object in MS Project
file (.mpp). I don't know how to do it in C#.
Manually, I can insert an object in .mpp file by going through following steps

1. Click on "Insert" tab,
2. Click on "Object...",
3. Select "Create from File:" radio button,
4. Click "Browse..." and select the file,
5. Click "OK" buton.


I want to get the same result with C# code (from an add-in project).

Please, can you help me on this.

Is it possible to make this inserted object invisible to the file user?

Thank you,
Anindya.
 
R

Rod Gill

Try recording a macro of you manually inserting the file. Then you can
translate the resulting code to C#. Note that when controlling office
applications, VB or VBA code is simpler, quicker and easier to write than C#
because C# doesn't have optional parameters or as good intellisense (I
think) and being able to record the hard parts makes it easier as well.

An alternative is to add hyperlinks to the xml file from the relevant task.
It's easy to follow a hyperlink or simply use its address to open the file
you want.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
A

Adam Behrle

I've looked into this quite a bit. Unfortunately Project doesn't
provide a way to programmatically insert an Object via code like other
office apps. Recording a macro shows the method that displays the
dialog for the user to insert the object, but that's as close as it
gets.

I believe it may be possible using some windows API tricks, but
haven't looked further.

Adam
QuantumPM
 
A

Anindya P

Hi,
Thank you for your responses.

Adam is right. Macro doesn't provide code for poped up dialog, which takes
the file info and inserts.

Please, let me know if you get more information.

Anindya.
 
L

Lars Hammarberg

Hello Anindya,

Here's a code snippet I did in VBA quite some time ago:
(I just added comments to explain the various steps)


Sub SelectAndEditEmbeddedExcelWorkbook()
'
'Lars Hammarberg, www.camako.se
'
Dim i As Long
Dim ctrl As CommandBarControl
Dim Start As Single

'Make sure the "Menu Bar" contains the "[OLE Object]&Object" control
(ID 30019):
Set ctrl = CommandBars(2).Controls.Add(ID:=30019, temporary:=True)

'Make sure embedded objects are visible:
Application.GanttShowDrawings True

'Switch over to the first OLE object in the Gantt Chart pane:
PaneNext
'your code could probably benefit from additional statements making sure
the view containing your objects is
'actually visible prior to the two lines above...


For i = 0 To 5 'breaking the (otherwise possibly infinite) loop after
5 tries...

'compare caption of ctrl 30019 (now showing caption of currently
selected object) to target object:
If Replace(ctrl.Caption, "&", "") <> "Worksheet Object" Then

'if not correct ole object, move to next ole object:
SendKeys "{TAB}, true"

'make sure the caption has time to change before retrieving
it again:
Start = Timer
Do While Timer < Start + 1 'second
DoEvents
Loop

Else

Debug.Print "found embedded excel workbook"

'send whatever verb you like to the OLE object:
ObjectVerb Verb:=0

Exit For

End If
Next


End Sub


/Lars Hammarberg
www.camako.se
 

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