• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to open embedded ppt file in edit mode without saving any changes on it when it closes.

iveskixs

New Member
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:

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
 
In case the above subject is not possible. My follow-up question would be, is it possible to delete added slides when it closes so that the embedded ppt file will still be the same.
 
Are you opening the file as Read Only? I don't see in your code where a file gets opened so I'm not too sure how that is setup.
 
Hi ,

I do not know what you mean by embedded Powerpoint file in Excel.

I commented out the following statement :

' oEmbFile.Verb Verb:=xlOpen

and the macro runs to completion with the Powerpoint presentation left open with one slide in it.

What exactly are you looking to do ?

Narayan
 
Hi,
I got the same that ppt auto saving the slides which needs to deleted on close.


You must be looking for this...

Code:
Sub PPT_GP()
'Add a reference to the Microsoft PowerPoint Library by:
    '1. Go to Tools in the VBA menu
    '2. Click on Reference
    '3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay

    'First we declare the variables we will be using
        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
    
    'Let's 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
      
        Dim x As Long
        For x = newPowerPoint.ActivePresentation.Slides.Count To 2 Step -1
            newPowerPoint.ActivePresentation.Slides(x).Delete
        Next x
     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
 
Hi ,

I do not know what you mean by embedded Powerpoint file in Excel.

I commented out the following statement :

' oEmbFile.Verb Verb:=xlOpen

and the macro runs to completion with the Powerpoint presentation left open with one slide in it.

What exactly are you looking to do ?

Narayan

The embedded ppt file is a ppt that I inserted in an excel file. It has 1 slide.

What I want to do is when I clicked the create presentation button it will open the embedded ppt file which will have the original 1st slide + the additional slide (Business Plan FY). Then, if i close the file the updates should not be saved..meaning the embedded file should only have the 1st slide only.

The problem is when i tried to click again the create presentation button the opened embedded ppt file has updates plus the additional slide which makes it 3 slides in total.
 
You must be looking for this...

Code:
Sub PPT_GP()
'Add a reference to the Microsoft PowerPoint Library by:
    '1. Go to Tools in the VBA menu
    '2. Click on Reference
    '3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay

    'First we declare the variables we will be using
        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
  
    'Let's 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
    
        Dim x As Long
        For x = newPowerPoint.ActivePresentation.Slides.Count To 2 Step -1
            newPowerPoint.ActivePresentation.Slides(x).Delete
        Next x
     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


Hi Deepak,

Where should I put the additional code that you suggest? wherein if I close the ppt file it will delete the additional slide/s. I think there is a need for If then Else statement here. What do you think? Please help. Thanks.

Code:
Dim x AsLong
       For x = newPowerPoint.ActivePresentation.Slides.Count To 2 Step -1
            newPowerPoint.ActivePresentation.Slides(x).Delete
Next x
 
Hi Deepak,

Where should I put the additional code that you suggest? wherein if I close the ppt file it will delete the additional slide/s. I think there is a need for If then Else statement here. What do you think? Please help. Thanks.

Code:
Dim x AsLong
       For x = newPowerPoint.ActivePresentation.Slides.Count To 2 Step -1
            newPowerPoint.ActivePresentation.Slides(x).Delete
Next x

Additional slide will get deleted each time you run the code.so need to worry just replace your code what i posted & check.
 
or add this...

Code:
If newPowerPoint.ActivePresentation.Slides.Count > 1 Then
    Dim x As Long
        For x = newPowerPoint.ActivePresentation.Slides.Count To 2 Step -1
            newPowerPoint.ActivePresentation.Slides(x).Delete
    Next x
End If
 
Back
Top