I am running a macro from excel that copies tables and charts into a PowerPoint template. If the template file is already open I'd like to set it as the presentation I'm going to work with and if it is not open I want to open it. I have tried to adapt a number of approaches that I found from other places but I could not get anything to work. Here are a few of the thing I tried:
Here is a function someone wrote and I modified somewhat that only does the checking to see if the presentation is open... however this also I could not get to work:
Any help is much appreciated. Thanks!
Code:
Dim pptPrs As PowerPoint.Presentation
Dim pptApp As PowerPoint.Application
Dim opnFlg As Boolean
opnFlg = False
For Each pptPrs In PowerPoint.Presentations
If pptPrs.Name = "template.pptx" Then
opnFlg = True
Set pptApp = GetObject(, objPrs)
pptApp.Visible = True
End If
Next
If opnFlg = False Then
Set pptApp = New PowerPoint.Application
pptApp.Visible = True
pptApp.Presentations.Open Filename:="C:\test\template.pptx"
End If
Here is a function someone wrote and I modified somewhat that only does the checking to see if the presentation is open... however this also I could not get to work:
Code:
Function IsPresentationOpen(strPresName As String) As Boolean
Dim oPresObject As PowerPoint.Presentation
Dim boolIsFullPath As Boolean
' Check to see whether the full path was passed.
If (InStr(1, strPresName, ":\")) = 0 Then
boolIsFullPath = False
Else
boolIsFullPath = True
End If
' Loop through the open presentations.
Set oPresObject = CreateObject("PowerPoint.Presentation")
For Each oPresObject In PowerPoint.Presentations
If boolIsFullPath = True Then
' Check for a match.
If (StrComp(oPresObject.FullName, strPresName, vbTextCompare) = 0) Then
IsPresentationOpen = True
Exit Function
End If
Else
' Check for a match.
If (StrComp(oPresObject.Name, strPresName, vbTextCompare) = 0) Then
IsPresentationOpen = True
Exit Function
End If
End If
Next oPresObject
' No match found.
IsPresentationOpen = False
End Function
Any help is much appreciated. Thanks!