Application (unknown member) invalid request. there is no activepresentation.

E

emailceloftis

Using VS2005, VB.NET
I am automating PowerPoint to delete an existing module, add a new
module then execute the module. The code below works great when
debugging... but when I let the execution flow without breakpoints the
following error is generated by the code module copied into the PPT
presentation:

Application (unknown member) invalid request. there is no active
presentation.

After the error the PPT object becomes visible - at that point I
notice that there is not presentation open, just a VB Editor in a
blank PPT frame.

I have tried inserting Thread.Sleep(2000) and oPres.Save() just before
the call the execute the module code, but I still get the same result.

Anyone have any idea what is going here?
 
S

Steve Rindsberg

Using VS2005, VB.NET
I am automating PowerPoint to delete an existing module, add a new
module then execute the module. The code below works great when
debugging... but when I let the execution flow without breakpoints the
following error is generated by the code module copied into the PPT
presentation:

Application (unknown member) invalid request. there is no active
presentation.

After the error the PPT object becomes visible - at that point I
notice that there is not presentation open, just a VB Editor in a
blank PPT frame.

I'm guessing the problem is here:

Dim oPres As PowerPoint.Presentation = appPPT.Presentations.Open

The equivalent in VBA won't compile because .Open takes several
parameters. Even if there's no error in .Net, the oPres object would be
null, so there'd be no active presentation for the subsequent statements
to act upon.

From PPT/VBA's object browser:

Function Open(FileName As String, [ReadOnly As MsoTriState], [Untitled
As MsoTriState], [WithWindow As MsoTriState = msoTrue]) As Presentation
 
E

emailceloftis

Using VS2005, VB.NET
I am automating PowerPoint to delete an existing module, add a new
module then execute the module. The code below works great when
debugging... but when I let the execution flow without breakpoints the
following error is generated by the code module copied into the PPT
presentation:
Application (unknown member) invalid request. there is no active
presentation.
After the error the PPT object becomes visible - at that point I
notice that there is not presentation open, just a VB Editor in a
blank PPT frame.

I'm guessing the problem is here:

Dim oPres As PowerPoint.Presentation = appPPT.Presentations.Open

The equivalent in VBA won't compile because .Open takes several
parameters. Even if there's no error in .Net, the oPres object would be
null, so there'd be no active presentation for the subsequent statements
to act upon.

From PPT/VBA's object browser:

Function Open(FileName As String, [ReadOnly As MsoTriState], [Untitled
As MsoTriState], [WithWindow As MsoTriState = msoTrue]) As Presentation

Here's the code that I've got:

Dim appPPT As New PowerPoint.Application
appPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
Dim oPres As PowerPoint.Presentation = appPPT.Presentations.Open
(DestinationPPT_Course_file,
Microsoft.Office.Core.MsoTriState.msoFalse, ,
Microsoft.Office.Core.MsoTriState.msoTrue)
'If the module already exists, delete it first
For Each Vbc As Microsoft.Vbe.Interop.VBComponent In
oPres.VBProject.VBComponents
If Vbc.Name.ToUpper = MODULE_NAME.ToUpper Then
oPres.VBProject.VBComponents.Remove(Vbc)
Exit For
End If
Next
'Insert updated code module...
oPres.VBProject.VBComponents.Add
(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule).CodeModule.AddFromFile
(Application.StartupPath & "\" & FILE_CODE_MODULE)
'Minimize PowerPoint
appPPT.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
Thread.Sleep(5000) 'After inserting this line my problem seems to
have disappeared - is this reasonable?
'Execute code module...
appPPT.Run("'" & _File_Name & "'!" & MODULE_NAME)

The above code works fine... the error was actually coming from the
Opened (and minimized) PowerPoint application. After inserting a
Thread.Sleep of 5 seconds the problem seems to have disappeared. Does
this seem reasonable to have to wait for the presentation to open?
Would saving the presentation help instead of sleeping?
 
E

emailceloftis

I'm guessing the problem is here:
Dim oPres As PowerPoint.Presentation = appPPT.Presentations.Open
The equivalent in VBA won't compile because .Open takes several
parameters.  Even if there's no error in .Net, the oPres object wouldbe
null, so there'd be no active presentation for the subsequent statements
to act upon.
From PPT/VBA's object browser:
Function Open(FileName As String, [ReadOnly As MsoTriState], [Untitled
As MsoTriState], [WithWindow As MsoTriState = msoTrue]) As Presentation

Here's the code that I've got:

   Dim appPPT As New PowerPoint.Application
   appPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
   Dim oPres As PowerPoint.Presentation = appPPT.Presentations.Open
(DestinationPPT_Course_file,
Microsoft.Office.Core.MsoTriState.msoFalse, ,
Microsoft.Office.Core.MsoTriState.msoTrue)
   'If the module already exists, delete it first
   For Each Vbc As Microsoft.Vbe.Interop.VBComponent In
oPres.VBProject.VBComponents
      If Vbc.Name.ToUpper = MODULE_NAME.ToUpper Then
         oPres.VBProject.VBComponents.Remove(Vbc)
         Exit For
      End If
   Next
   'Insert updated code module...
   oPres.VBProject.VBComponents.Add
(Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_StdModule).CodeModule..A ddFromFile
(Application.StartupPath & "\" & FILE_CODE_MODULE)
   'Minimize PowerPoint
   appPPT.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
   Thread.Sleep(5000) 'After inserting this line my problem seems to
have disappeared - is this reasonable?
   'Execute code module...
   appPPT.Run("'" & _File_Name & "'!" & MODULE_NAME)

The above code works fine... the error was actually coming from the
Opened (and minimized) PowerPoint application. After inserting a
Thread.Sleep of 5 seconds the problem seems to have disappeared. Does
this seem reasonable to have to wait for the presentation to open?
Would saving the presentation help instead of sleeping?

After further investigation the problem was related to the WithWindow
parameter on the oPres.Open method. As you noted in your response
above it needs to be Microsoft.Office.Core.MsoTriState.msoTrue for the
module code to be able to use the ActivePresentation method. In
conclusion, setting WithWindow to
Microsoft.Office.Core.MsoTriState.msoTrue solved my problem (I took
out the sleep statement).
 

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