+ Reply to Thread
Results 1 to 1 of 1

Saving PPT file using VBA

  1. #1
    Registered User
    Join Date
    02-25-2015
    Location
    new York
    MS-Off Ver
    2013
    Posts
    4

    Saving PPT file using VBA

    Hi all,

    I am trying to create, edit and save a ppt file using Excel 2013 VBA, but the PowerPoint application keeps crashing whenever it tries to save the file. I adopted the code from some website, and am trying to make some modification to it so that it can save the file each time there is an update. I will be extremely grateful is someone can take a look at my a few lines of VBA code and advise me with a solution.

    Thank you very much for your help!

    VBA code:
    Sub CreatePowerPoint()

    '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 cht As Excel.ChartObject

    '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

    newPowerPoint.ActivePresentation.SaveAs Filename:="C:\Users\bulin_000\Documents\New Folder\test.ppt"
    '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 + 1, ppLayoutText
    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.Paste.Select
    '(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 = 125

    activeSlide.Shapes(2).Width = 200
    activeSlide.Shapes(2).Left = 505

    newPowerPoint.ActivePresentation.Save

    Next

    Set activeSlide = Nothing
    Set newPowerPoint = Nothing

    End Sub
    Attached Files Attached Files

+ 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. Replies: 11
    Last Post: 08-23-2014, 01:28 PM
  2. Replies: 5
    Last Post: 09-13-2012, 11:50 AM
  3. Problem saving Excel file that copies an embedded object from a separate file
    By bhodge10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2012, 02:47 PM
  4. Creating a .txt file extracting information from a Excel file saving as .resx file
    By AbdallahHajbed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2012, 09:00 AM
  5. Saving multi-tab excel file created from comma delimited text file
    By Marcus Aurelius in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2005, 01:20 PM

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