+ Reply to Thread
Results 1 to 10 of 10

Help in macro to create a PPT of Graphs

  1. #1
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Help in macro to create a PPT of Graphs

    Hi,
    I have this following code to create the PPT with a specific template. But in this, the first slide of the PPT are coming blank. How to remove those blank slides?
    PHP Code: 
    Sub CreatePowerPoint()




    Answer MsgBox("Are you sure you want to continue?" vbNewLine "Clicking 'YES' will create the DU Dashboard PPT" vbNewLine "You may want to set the range & Update VOC graph"vbYesNoCancel vbInformation"Warning: DU Dashboard graph")

    If 
    Answer vbYes Then Else Exit Sub

     
    '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 Librarycheck 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 cht As Excel.ChartObject
         Dim PPT As PowerPoint.Application
     Set PPT = New PowerPoint.Application
     PPT.Visible = True
     PPT.Presentations.Open Filename:="Z:\Monthly Reports\DU Dashboard\DU Dashboard Template.pptx"
         '
    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
         
        '
    Show the PowerPoint
            newPowerPoint
    .Visible True
        
        
    'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
            For Each cht In ActiveSheet.ChartObjects
            
            '
    Add a new slide where we will paste the chart
                newPowerPoint
    .ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count 1ppLayoutText
                newPowerPoint
    .ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
                Set activeSlide 
    newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
                    
            
    'Copy the chart and paste it into the PowerPoint as a Metafile Picture
                cht.Select
                ActiveChart.ChartArea.Copy
                activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
        
            '
    Set the title of the slide the same as the title of the chart
                activeSlide
    .Shapes(1).TextFrame.TextRange.Text cht.Chart.ChartTitle.Text
                
            
    'Adjust the positioning of the Chart on Powerpoint Slide
                newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15
                newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 80
            
                activeSlide.Shapes(2).Width = 200
                activeSlide.Shapes(2).Left = 505
                
            Next
         
        AppActivate ("Microsoft PowerPoint")
        Set activeSlide = Nothing
        Set newPowerPoint = Nothing
         
    End Sub 
    Last edited by akhileshgs; 04-24-2014 at 02:51 AM.
    Please make the Post as solved, when you get your answer & Click * if you like my suggestion

  2. #2
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    If it is not possible, can you please give me the code to delete the first slide of the PPT once the above macro finishes it work?

  3. #3
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    comments removing
    Attached Files Attached Files
    Last edited by akhileshgs; 04-25-2014 at 09:03 AM. Reason: delete

  4. #4
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    Hi,
    Can anyone pls help me?

  5. #5
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs


  6. #6
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    Help Please

  7. #7
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    Can anybody pls help?

  8. #8
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Help in macro to create a PPT of Graphs

    Yes! I found a solution that works for. In your Template.pptx make sure you only have one slide (the title slide). Remove all other slides, the code will then paste from slide 2

  9. #9
    Registered User
    Join Date
    02-16-2012
    Location
    sa
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Help in macro to create a PPT of Graphs

    I found a solution for pasting from slide 2. Check your thread

  10. #10
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Help in macro to create a PPT of Graphs

    This code will delete the first slide
    PHP Code: 
    Sub DeleteFirstSlideInPresentation()

    Dim PPApp As PowerPoint.Application
    Dim PPPres 
    As PowerPoint.Presentation
    Dim PPSlide 
    As PowerPoint.Slide

     
    Set PPApp 
    GetObject(, "Powerpoint.Application")
     
    Set PPPres PPApp.ActivePresentation
     
    Set PPSlide 
    PPPres.Slides(1)

    PPSlide.Delete
      
    End Sub 
    Thanks to Sweep for his help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro to create multiple graphs
    By westlife in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2012, 02:38 PM
  2. macro to create the same graphs for different worksheets
    By chemeng1T3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2012, 02:37 AM
  3. macro to create multiple graphs
    By khansen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-05-2009, 01:47 PM
  4. macro to create line graphs
    By Pasha81 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-05-2009, 11:34 AM
  5. A macro to create multiple graphs
    By AmyTaylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-04-2005, 06:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1