Appreciate any help.
Problem:
I have an embedded powerpoint file in excel. Now, I have a code that opens that embedded file in edit mode and paste the charts from excel to ppt. However, when I just close the ppt file and try to run again the code to open it, it has the charts that was pasted the last time I run the code. What should be the code to open the embedded ppt file in edit mode without saving any changes on it?
Here is my code:
Problem:
I have an embedded powerpoint file in excel. Now, I have a code that opens that embedded file in edit mode and paste the charts from excel to ppt. However, when I just close the ppt file and try to run again the code to open it, it has the charts that was pasted the last time I run the code. What should be the code to open the embedded ppt file in edit mode without saving any changes on it?
Here is my code:
Code:
Sub PPT_GP()
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim tblchrt As String
Dim oEmbFile As Object
'// Opens object
Application.DisplayAlerts = False
Set oEmbFile = ThisWorkbook.Sheets("COMPONENTS OF GROWTH").OLEObjects("Object 2")
oEmbFile.Verb Verb:=xlOpen
'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'create a new PowerPoint
If newPowerPoint Is Nothing Then
Set newPowerPoint = New PowerPoint.Application
End If
'Make a presentation in PowerPoint
If newPowerPoint.Presentations.Count = 0 Then
newPowerPoint.Presentations.Add
End If
tblchrt = "G6:U20"
'Show the PowerPoint
newPowerPoint.Visible = True
'Add a new slide where we will paste the chart
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutTitleOnly
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
'Set the title of the slide the same as the title of the chart
activeSlide.Shapes(1).TextFrame.TextRange.Text = "Business Plan FY"
'Adjust the positioning of the Chart on Powerpoint Slide
Sheets("COMPONENTS OF GROWTH").Range(tblchrt).CopyPicture Appearance:=xlScreen, Format:=xlPicture
activeSlide.Shapes.Paste.Select
newPowerPoint.ActiveWindow.Selection.ShapeRange.Align msoAlignBottoms, True
newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 110
newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 30
newPowerPoint.ActiveWindow.Selection.ShapeRange.Width = 650
Application.DisplayAlerts = True
AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set newPowerPoint = Nothing
Set oEmbFile = Nothing
End Sub