PDA

View Full Version : Error creating PP slide from Excel within IE



grime
03-08-2010, 06:11 AM
Over 3 years since my last post. Hoping you all are as helpful as you were last time. : pray2:

I have VBA code (within my Excel document) that, which a user clicks a button, creates a PowerPoint slide out of the Excel information. If PowerPoint is not currently open, it opens PP and creates a new document with the information as slide #1. If an open PP presentation exists, it creates the new slide as the last slide of the presentation. Code is as follows:



Private Sub PowerPoint()
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim oTop As Double, oHeight As Double
Dim LockShape As Shape
Application.ScreenUpdating = False

' Reference instance of PowerPoint
On Error Resume Next
' Check whether PowerPoint is running
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then
' PowerPoint is not running, create new instance
Set PPApp = CreateObject("PowerPoint.Application")
' For automation to work, PowerPoint must be visible
PPApp.Visible = True
End If
On Error GoTo 0
' Reference presentation and slide
On Error Resume Next
If PPApp.Windows.Count > 0 Then
' If there is at least one presentation, use existing presentation
Set PPPres = PPApp.ActivePresentation
' Use active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Else
' If there are no presentations, create new presentation
Set PPPres = PPApp.Presentations.Add
End If
On Error GoTo 0
' Some PowerPoint actions work best in normal slide view
PPApp.ActiveWindow.ViewType = ppViewSlide
' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex


Here's my issue... The Excel document that contains this code is located on the web. If the user clicks the link to the Excel document, it gives him the option to OPEN or SAVE. If he SAVEs it, then opens it locally, there's no issue; the code works perfectly. If he OPENs it, the document opens within Internet Explorer and the user gets an error if they try to run the code without PP being open (it does work if PP is already open though).

My plan is to just ZIP the Excel file, which will force the user to open locally, but I am wondering if there VBA code that will check if the Excel document is opened in the web browswer?

Thanks in advance.