Prev: Auto generate an index from a style
Next: Carriage Return Symbol Text Field Word Form VBA Problem inside Tab
From: Karen53 on 3 Mar 2010 10:13 Hi, Is there a way to open an existing Powerpoint presentation and work with it from within Word VBA? -- Thanks for your help. Karen53
From: Pesach Shelnitz on 3 Mar 2010 13:09
Hi Karen, Yes, it is possible. The following macro is the basic skeleton for opening a PowerPoint presentation from Word. It is possible to exchange data between Word and the presentation and to perform other VBA tasks on the presentation. If you need more help, you'll have to write back and describe what you want the macro to do to the presentation. Sub PowerPointFromWord() Const Error_FileNotFound = 1004 Const Error_NotRunning = 429 Const Error_NotInCollection = &H80048240 Dim fileName As String Dim pptName As String Dim pptApp As Object Dim MyPresentation As Object Dim newInstance As Boolean With Application.FileDialog(msoFileDialogFilePicker) .InitialFileName = "*.ppt" If .Show Then fileName = .SelectedItems(1) Else MsgBox "You didn't select a PowerPoint file to open." Exit Sub End If End With k = InStrRev(fileName, "\", -1, vbTextCompare) If k > 0 Then pptName = Right(fileName, Len(fileName) - k) Else MsgBox "A suitable file was not selected." Exit Sub End If On Error Resume Next Set pptApp = GetObject(, "PowerPoint.Application") If Err.Number = Error_NotRunning Then Set pptApp = CreateObject("PowerPoint.Application") newInstance = True Else newInstance = False End If On Error GoTo 0 pptApp.Visible = True On Error Resume Next Set MyPresentation = pptApp.Presentations(pptName) If Err.Number = Error_NotInCollection Then Err.Clear Set MyPresentation = pptApp.Presentations.Open(fileName) If Err.Number = Error_FileNotFound Then MsgBox "The file specified could not be opened.", _ vbCritical Or vbOKOnly, "File Not Opened" Set pptApp = Nothing Exit Sub End If End If On Error GoTo 0 ' Replace the following message with code to perform tasks. ' The message will appear in Word, and the macro will end ' after you click OK. MsgBox MyPresentation.FullName & " is now open in PowerPoint." If newInstance = True Then pptApp.Quit End If Set MyPresentation = Nothing Set pptApp = Nothing End Sub -- Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "Karen53" wrote: > Hi, > > Is there a way to open an existing Powerpoint presentation and work with it > from within Word VBA? > -- > Thanks for your help. > Karen53 |