SYMPTOMS
When you attempt to run a Visual Basic for Applications macro that creates or opens a PowerPoint presentation, you may receive the following or similar error message:
Run-time error '-2147188160 (80048240)':
Application (unknown member): Invalid request. There is no currently active document window.
The same macro runs without error with Office 97.
CAUSE
This behavior is caused by using any PowerPoint ActiveWindow or ActivePresentation property, method, or event when the PowerPoint program is not visible. The following sample code will cause this error:
Sub A()
Dim oPpt As PowerPoint.Application
Set oPpt = New PowerPoint.Application
oPpt.Presentations.Add
oPpt.Presentations(1).Slides.Add 1, ppLayoutBlank
'The following line causes the run-time error
msgbox oPpt.ActiveWindow.Caption
End Sub
NOTE: This error message does not occur in PowerPoint 97.
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals can
help explain the functionality of a particular procedure, but they will not
modify these examples to provide added functionality or construct procedures to
meet your specific needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
To work around this behavior, add the following lines of code once in any sub procedure before any ActiveWindow or ActivePresentation calls:
If PowerPoint.Application.Version >= 9 Then
'window must be visible
PowerPoint.Application.Visible = msoTrue
End If
This code makes PowerPoint visible for PowerPoint 2000 and later versions. PowerPoint 97 does not need to be made visible. The sample code in the Cause section would change to:
Sub A()
Dim oPpt As PowerPoint.Application
Set oPpt = New PowerPoint.Application
oPpt.Presentations.Add
oPpt.Presentations(1).Slides.Add 1, ppLayoutBlank
If oPpt.Version >= 9 Then
'window must be visible
oPpt.Visible = msoTrue
End If
oPpt.ActiveWindow.View.GotoSlide 1
End Sub