This project has moved. For the latest updates, please go here.

Working Word Add-in to PowerPoint

Mar 8, 2013 at 8:59 AM
Hello,
My company managed to implement an Add-in that imports objects from a file by drag and drop into Word and to generate automatic report.
All has been done for Word and I'm stuck in some code patt to change the implementation to PowerPoint.

I don't find any example which does this, nor for PowerPoint, nor for Excel.

I put the WordApi in comments in "//" that must be replaced with Powerpoint application, but it requires an object. But my code doesn't work properly, since I don't find a way how to give an object as reference to a NetOffice.PowerPointApi.Application

public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
    {
        //_application = new NetOffice.WordApi.Application(null, Application); before
        _application = new NetOffice.PowerPointApi.Application();
        // If the addin not connected during startup, we call OnStartupComplete at hand
        if (ConnectMode != ext_ConnectMode.ext_cm_Startup)
            OnStartupComplete(ref custom);
    }

Because later, when I try to execute:

ctpFactory = new NetOffice.OfficeApi.ICTPFactory(_application, CTPFactoryInst);

It doesn't work since I didn't give any object to _application.

Any suggestion how this could be fixed?

Thanks.
Developer
Mar 8, 2013 at 9:34 AM
I suppose you'd better get PowerPoint application reference with common NetOffice way (like you did in a Word addin).
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
        //_application = new NetOffice.WordApi.Application(null, Application); before
        _application = new NetOffice.PowerPointApi.Application(null, Application);
 }
Mar 12, 2013 at 10:40 AM
Hi,

I could manage the difference, but now I'm stuck with something else.
        foreach (NetOffice.WordApi.InlineShape s in docWord.InlineShapes)
            {
                #region Set Shapes
                if (s.Type==NetOffice.WordApi.Enums.WdInlineShapeType.wdInlineShapePicture &&  s.AlternativeText.Contains("|"))
                {
                  <some code>
                }
             }
How can I use NetOffice.WordApi.Enums.WdInlineShapeType.wdInlineShapePicture for PowerPoint?

I thought about
             foreach (NetOffice.PowerPointApi.Slide slide in presentation.Slides)
            {
                    foreach (NetOffice.PowerPointApi.Shape shape in slide.Shapes)
                    {
                        #region Set Shapes
                        if (shape.Type == NetOffice.PowerPointApi.Enums.WdInlineShapeType.wdInlineShapePicture && shape.AlternativeText.Contains("|"))
                        {
                           <some code>
                        }
                     }
             }
But NetOffice.PowerPointApi.Enums.WdInlineShapeType.wdInlineShapePicture doesn't exists and doesn't work in such a way.

Someone any idea?

Thanks.
Mar 20, 2013 at 10:45 AM
Edited Mar 20, 2013 at 4:44 PM
artnib wrote:
I suppose you'd better get PowerPoint application reference with common NetOffice way (like you did in a Word addin).
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
        //_application = new NetOffice.WordApi.Application(null, Application); before
        _application = new NetOffice.PowerPointApi.Application(null, Application);
 }
Hi,
the if-loop was replaced by
if (shape.Type.ToString().Equals("msoAutoShape") && shape.AlternativeText.Contains("|"))
{
          <some code>
}
I could manage the initial post too. While simply doing the same like for WordApi, I was missing the PowerPointApi and I wrote some wrong code somewhere else, that's why it didn't work properly.
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
            _application = new NetOffice.PowerPointApi.Application(null, Application);
            if (ConnectMode != ext_ConnectMode.ext_cm_Startup)
                OnStartupComplete(ref custom);
}
But still the issue with ctpFactory remains.
public void CTPFactoryAvailable(object CTPFactoryInst)
        {
            try
            {
                ctpFactory = new NetOffice.OfficeApi.ICTPFactory(_application, CTPFactoryInst);
It says that it is impossible to convert NetOffice.PowerPointApi.Application in LateBindingApi.Core.COMObject and it says that that NetOffice.OfficeApi.ICTPFactory has invalid arguments.

I declared at beginning:
        ICTPFactory ctpFactory;

        public Addin()
        {
            LateBindingApi.Core.Factory.Initialize();
        }
Those are all informations I have so far.

This error implies that, when I drag and drop my object from Add-In in PowerPoint, I get following error:
Source:LateBindingApi.Core
TargetSite:System.Object PropertyGet(LateBindingApi.Core.COMObject, System.String, System.Object[])
Message:See inner exception for details.
Message:Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
StackTrace: at LateBindingApi.Core.Invoker.PropertyGet(COMObject comObject, String name, Object[] paramsArray)
at NetOffice.WordApi._Application.get_ActiveDocument()
at ProgramOffice.PPTAddIn.ProgramViewItemDragSource.EndDrag(Object dragObject, DragDropEffects effect) in E:\app\ProgramOfficePPT\Source\ProgramOffice.PPTAddIn\ProgramViewItemDragSource.cs:line 108
The strange part is, that nowhere in my code I have NetOffice.WordApi._Application.get_ActiveDocument()

And the line 108 code is:
    public override void EndDrag(object dragObject, System.Windows.Forms.DragDropEffects effect)
    {
        ProgramViewItem item=(dragObject as ProgramViewItem);
        Debugger.Write("EndDrag " + item.ItemName);
        base.EndDrag(dragObject, effect);
    }
And ProgramViewItem is a DataObject
Mar 22, 2013 at 4:24 PM
Edited Mar 22, 2013 at 4:58 PM
THANK YOU SEBASTIAN!!!!!!!!!!!

I just finished my project today with your help!!!!

I had just to change a bit of code and it finally works to auto update all I need ^^

Now, let's implement it in Excel too ( Proven it works in PowerPoint / checked ).
Coordinator
Mar 23, 2013 at 3:47 PM
cool! gimme a copy whent its done (thesis) :)

Sebastian
Mar 25, 2013 at 8:17 AM
Maybe a reduced copy ;)

Mike