How Do I Create a Macro in XLS to Export a Chart to PowerPoint?

How Do I Create a Macro in XLS to Export a Chart to PowerPoint? thumbnail
Create a macro in Excel to export a chart to PowerPoint.

Microsoft Excel is a spreadsheet application that can be used to analyze data and create charts. Microsoft PowerPoint is used to create presentations. Knowing how to export an Excel chart to PowerPoint using a macro can streamline the process of preparing presentations, because the macro automates the exporting phase.

Instructions

    • 1

      Start Microsoft Excel 2007 and type the following:

      In column "A1" type "1". In column "B1" type "0.5".

      In column "A2" type "2". In column "B2" type "0.2".

      In column "A3" type "3". In column "B3" type "0.7".

      In column "A4" type "4". In column "B4" type "0.1".

      In column "A5" type "5". In column "B5" type "0.9".

      Highlight "A1" to "B5," click the "Insert" menu and select "Line" to create a line chart.

    • 2

      Select the "Developer" tab and click "Record Macro." Click "A1" and select "Stop Recording." Click "Macros" and select "Macro1." Click "Edit" to open Microsoft Visual Basic.

      Click the "Tools" menu and check the box next to "Microsoft PowerPoint 12.0 Object Library." Select "OK."

    • 3

      Type the following inside "Sub Macro1" to declare your variables:

      Dim myPath As String

      Dim ppApp As PowerPoint.Application

      Dim ppPresentation As PowerPoint.Presentation

      Dim ppSlide As PowerPoint.Slide

      Dim ppImage As PowerPoint.Shape

    • 4

      Type the following to save the new chart you have just created:

      ActiveSheet.ChartObjects("Chart 1").Activate

      myPath = "C:\myChart.gif"

      ActiveChart.Export Filename:=myPath, FilterName:="GIF"

      You can edit "myPath = "C:\myChart.gif"" to save the chart to a different path.

    • 5

      Type the following to create a new PowerPoint presentation and add one blank slide:

      Set ppApp = New PowerPoint.Application

      ppApp.Visible = msoTrue

      Set ppPresentation = ppApp.Presentations.Add(msoTrue)

      ppPresentation.Slides.Add 1, ppLayoutBlank

    • 6

      Type the following to add your Excel chart and save the presentation:

      Set ppSlide = ppPresentation.Slides(1)

      ppSlide.Shapes.AddPicture Filename:=myPath, _

      LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, _

      Left:=100, Top:=100, Width:=250, Height:=250

      ppPresentation.SaveAs "G:\myExcelChartPresentation.ppt"

      ppPresentation.Close

      ppApp.Quit

      You can edit "ppPresentation.SaveAs "G:\myExcelChartPresentation.ppt"" to save your presentation in a different path.

    • 7

      Type the following to release your variables from memory:

      Set ppSlide = Nothing

      Set ppPresentation = Nothing

      Set ppApp = Nothing

      Press "F5" to run your macro.

Related Searches:

References

  • Photo Credit chart background image by Stasys Eidiejus from Fotolia.com

Comments

You May Also Like

Related Ads

Featured