none
Problem with powerpoint method CommandBars.ExecuteMso("PasteSourceFormatting") RRS feed

  • Question

  • We have an application which copies slides from one presentation to other presentation. We are using method _presentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting") to paste the slides. This method is usefull is keeping the source formatting of the slides.

    But we are facing a problem with this method. If we use this method then powerpoint window must be set to visible

    pptApp = New PowerPoint.Application

    pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue

    other wise .ExecuteMso("PasteSourceFormatting") does not work and slide does not paste in target presentation.  This statement executes successfully. No error occurs while executing ( or debugging) this statement but slide is not pasted into target presentation. When we run the application on any machine then we have to take care of keep windows session alive i.e. windows should not get locked.

    We are trying to run this application as windows service mode but in windows service mode powerpoint window does not appear. So slide paste fails everytime ExecuteMso("PasteSourceFormatting") is executed.

    Is there anyway to make ExecuteMso("PasteSourceFormatting") method to work successfully without keeping powerpoint window open or getting slide pasted in anyway?

    Please help!!!

    Thanks,

    Dinesh


    Dinesh

    Wednesday, January 16, 2013 11:47 AM

All replies

  • I am working on a VBA application which automates Powerpoint.  When application runs the statement ExecuteMso("PasteSourceFormatting"), slides does not paste in new Presentation.  If an attempt is made to access the newly pasted slide it results in error as,

    Exception: System.Runtime.InteropServices.COMException
    Message: Slides (unknown member) : Integer out of range. 1 is not in the valid range of 1 to 0.
    Source: Microsoft PowerPoint 2010

    Could anyone please share some pointers on this problem?

    Thanks,

    Dinesh


    Dinesh

    Monday, January 14, 2013 8:35 AM
  • Hi Dinesh,

    Thank you for posting in the MSDN Forum.

    Could you please provide all your code? It might be helpful for troubleshooting.

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 15, 2013 4:29 AM
    Moderator
  • Thanks for reply.

    I can not provide the complete code since it is quite large but I am pasting the code which is using method ExecuteMso("PasteSourceFormatting").


    ppPresSource = _colSourcePres.GetPresentation(CopynGetTempFile(mySlide.PptFileName), _presentation)

    sldSource = ppPresSource.Slides(mySlide.SlideIndex)

    'Copy from source, paste in destination

    log.Info("Copying source slide and activating the target presentation")

    sldSource.Copy()

    log.Info("Activating presentation...")

    _presentation.Windows(1).Activate()

    log.Info("Presentation activated")

    If _presentation.Slides.Count > 0 Then

    _presentation.Slides(_presentation.Slides.Count).Select()

    End If

    _presentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")

    log.Info("Slide pasted with source formatting")

    log.Info("Get a reference on the inserted slide")

    sldInserted = _presentation.Slides(slideIndex)

    If we use this method ExecuteMso("PasteSourceFormatting") then powerpoint window must be set to visible

    pptApp = New PowerPoint.Application

    pptApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue

    other wise .ExecuteMso("PasteSourceFormatting") does not work and slide does not paste in target presentation.  This statement executes successfully. No error occurs while executing ( or debugging) this statement but slide is not pasted into target presentation. When we run the application on any machine then we have to take care of keep windows session alive i.e. windows should not get locked.

    We are trying to run this application as windows service but in windows service mode powerpoint window does not appear. So slide paste fails everytime ExecuteMso("PasteSourceFormatting") is executed.

    Is there anyway to make ExecuteMso("PasteSourceFormatting") method to work successfully without keeping powerpoint window open or getting slide pasted in anyway?

    Thanks,

    Dinesh


    Dinesh

    Wednesday, January 16, 2013 11:57 AM
  • Hi Dinesh

    <<We are trying to run this application as windows service mode but in windows service mode powerpoint window does not appear. >>

    The Office applications were NOT designed to be run as a "service". They are expressly end-user applications and meant to be run on a local machine with user supervisions. Some things simply do not and cannot function when the applications are not visible.

    If you need create or manipulate PowerPoint presentations as part of a windows service, I recommend you look into using the Office Open XML file formats, probably using the Open XML SDK. You can find more information at OpenXMLDeveloper.org about the concept, in general. Information on the OPen XML SDK can also be found on MSDN and there is an Open XML SDK forum.

    It is important to note, however, that this is more easily done using a .NET Framework programming language. VBA does not have the XML or Zip package tools to work with the Office Open XML file formats...


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 16, 2013 4:36 PM
    Moderator
  • Hi Cindy,

    We are using .Net 4 framework and Microsoft PowerPoint 14.0 Object Library (Microsoft.Office.Interop.PowerPoint.dll). I can run my application in service mode on my system Windows XP. There are two modes to run service, as local system account and this account (local or domain user account). I am a user of administrators group (domain user).  

    When I run application in any mode it works to create presentation and no failure with ExecuteMso("PasteSourceFormatting"). Powerpoint winodw is not visible in service mode. It works perfectly. But on different systems it works different way. on Windows server 2008 system running application under local system account works perfectly but it does not work under this account. On windows 7 it doesnot work in both user mode and ExecuteMso("PasteSourceFormatting") method fails to paste the slides.

    So I am not getting what exactly needs to be done to get application (ExecuteMso("PasteSourceFormatting") method ) running right.

    Is it related to user permissions running the service or the security settings of the windows environment or there are limitations of using ExecuteMso("PasteSourceFormatting") ?

    Could anyone please explain how ExecuteMso("PasteSourceFormatting") this method works with powerpoint?

    Thanks,

    Dinesh


    Dinesh

    Thursday, January 17, 2013 7:27 AM
  • Any difference between the version of those Office you have?

    Thursday, January 17, 2013 9:11 AM
  • There is no difference in office version.

    Dinesh

    Monday, February 4, 2013 9:36 AM
  • Hi Dinesh,

    Just wondering if you ever worked out a method for solving the issues you experienced here?  I am experiencing a similar problem and was curious what ended up working for you, if anything?

    Monday, September 23, 2013 5:46 AM