Tuesday, June 28, 2011

Copy range from Excel and paste as picture in PowerPoint Slide

If you want to copy the range as picture and paste it into PowerPoint slide .  Try this macro

Download Working File

'Copy range from Excel and paste as picture in ppt

Sub export_to_ppt()

'In tools Reference add Microsoft PowerPoint

Dim PPApp           As PowerPoint.Application
Dim PPPres          As PowerPoint.Presentation
Dim PPSlide         As PowerPoint.slide
Dim SlideCount      As Integer
Dim shptbl          As Table

    Set PPApp = New PowerPoint.Application
    PPApp.Visible = True
    'create new ppt
    Set PPPres = PPApp.Presentations.Add
    'count no of slides
    SlideCount = PPPres.Slides.Count
    'set layout of slide
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutTitleOnly)
    'add header
    PPSlide.Shapes(1).TextFrame.TextRange.Text = Sheets(1).Range("A1").Value

    'format header
    With PPSlide.Shapes(1).TextFrame.TextRange.Characters
        .Font.Size = 30
        .Font.Name = "Arial"
        .Font.Color = vbWhite
    End With
    With PPSlide.Shapes(1)
        .Fill.BackColor.RGB = RGB(79, 129, 189)
        .Height = 50
    End With
    Sheets(1).Range("a3:c9").CopyPicture Appearance:=xlScreen, Format:=xlPicture ' Copy range as picture
    PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex ' activate the slide no
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing
End Sub

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...