+ Reply to Thread
Results 1 to 4 of 4

Copy data from excel sheet to powerpoint

Hybrid View

amid Copy data from excel sheet to... 08-04-2009, 09:29 AM
tony h Re: Copy data from excel... 08-05-2009, 08:18 AM
amid Re: Copy data from excel... 08-06-2009, 05:12 AM
amid Re: Copy data from excel... 08-06-2009, 10:23 AM
  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Copy data from excel sheet to powerpoint

    Hi,

    I am looking to copy some data from an excel sheet to an already existing powerpoint presentation. I do not want to open a new instance of powerpoint but paste the selected data into an already existing ppt. Can anyone help me out with this?

    Thanks,
    Amid.

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Copy data from excel sheet to powerpoint

    Is this something you want to do manually or automatically. A bit more background information about how and when and why would help. Is it always the same info to the same place?

    If it is a one off copy and paste should work

  3. #3
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Copy data from excel sheet to powerpoint

    Hi,

    I am looking to copy data from 48 sheets in a workbook onto a powerpoint presentation. The range of data differs from sheet-to-sheet. I have a macro that copies data from a single worksheet and pastes it onto a ppt slide. Here is tha macro I am using:

    Sub Copy_Paste_to_PowerPoint()
    
    'Requires a reference to the Microsoft PowerPoint Library via the Tools - Reference menu in the VBE
    Dim ppApp As PowerPoint.Application
    Dim ppSlide As PowerPoint.Slide
    
    Dim SheetName As String
    Dim TestRange As Range
    Dim TestSheet As Worksheet
    Dim TestChart As ChartObject
    
    Dim PasteChart As Boolean
    Dim PasteChartLink As Boolean
    Dim ChartNumber As Long
    
    Dim PasteRange As Boolean
    Dim RangePasteType As String
    Dim RangeName As String
    Dim AddSlidesToEnd As Boolean
    Dim shts As Worksheet
    'Parameters
    
    'SheetName - name of sheet in Excel that contains the range or chart to copy
    
    'PasteChart -If True then routine will copy and paste a chart
    'PasteChartLink -If True then Routine will paste chart with Link; if = False then paste chart no link
    'ChartNumber -Chart Object Number
    '
    'PasteRange - If True then Routine will copy and Paste a range
    'RangePasteType - Paste as Picture linked or unlinked, "HTML" or "Picture". See routine below for exact values
    'RangeName - Address or name of range to copy; "B3:G9" "MyRange"
    'AddSlidesToEnd - If True then appednd slides to end of presentation and paste. If False then paste on current slide.
    
    'use active sheet. This can be a direct sheet name
    
    
    
    SheetName = Sheet2.Name
    
    'Setting PasteRange to True means that Chart Option will not be used
    PasteRange = True
    RangeName = ("b2:g16") '"MyRange"
    RangePasteType = "Picture"
    RangeLink = True
    
    PasteChart = False
    PasteChartLink = True
    ChartNumber = 1
    
    AddSlidesToEnd = False
    
    
    'Error testing
    On Error Resume Next
    Set TestSheet = Sheets(SheetName)
    Set TestRange = Sheets(SheetName).Range(RangeName)
    Set TestChart = Sheets(SheetName).ChartObjects(ChartNumber)
    On Error GoTo 0
    
    If TestSheet Is Nothing Then
    MsgBox "Sheet " & SheetName & " does not exist. Macro will exit", vbCritical
    Exit Sub
    End If
    
    If PasteRange And TestRange Is Nothing Then
    MsgBox "Range " & RangeName & " does not exist. Macro will exit", vbCritical
    Exit Sub
    End If
    
    If PasteRange = False And PasteChart And TestChart Is Nothing Then
    MsgBox "Chart " & ChartNumber & " does not exist. Macro will exit", vbCritical
    Exit Sub
    End If
    
    
    'Look for existing instance
    On Error Resume Next
    Set ppApp = GetObject(, "PowerPoint.Application")
    On Error GoTo 0
    
    'Create new instance if no instance exists
    If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
    'Add a presentation if none exists
    If ppApp.Presentations.Count = 0 Then ppApp.Presentations.Add
    
    'Make the instance visible
    ppApp.Visible = True
    
    'Check that a slide exits, if it doesn't add 1 slide. Else use the last slide for the paste operation
    If ppApp.ActivePresentation.Slides.Count = 0 Then
    Set ppSlide = ppApp.ActivePresentation.Slides.Add(1, ppLayoutBlank)
    Else
    If AddSlidesToEnd Then
    'Appends slides to end of presentation and makes last slide active
    ppApp.ActivePresentation.Slides.Add ppApp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
    ppApp.ActiveWindow.View.GotoSlide ppApp.ActivePresentation.Slides.Count
    Set ppSlide = ppApp.ActivePresentation.Slides(ppApp.ActivePresentation.Slides.Count)
    Else
    'Sets current slide to active slide
    Set ppSlide = ppApp.ActiveWindow.View.Slide
    End If
    End If
    
    'Options for Copy & Paste Ranges and Charts
    If PasteRange = True Then
    'Options for Copy & Paste Ranges
    If RangePasteType = "Picture" Then
    'Paste Range as Picture
    Worksheets(SheetName).Range(RangeName).Copy
    ppSlide.Shapes.PasteSpecial(ppPasteDefault, link:=RangeLink).Select
    ppApp.ActiveWindow.Selection.ShapeRange.Left = 50
    ppApp.ActiveWindow.Selection.ShapeRange.Top = 100
    
    Else
    'Paste Range as HTML
    Worksheets(SheetName).Range(RangeName).Copy
    ppSlide.Shapes.PasteSpecial(ppPasteHTML, link:=RangeLink).Select
    End If
    Else
    'Options for Copy and Paste Charts
    Worksheets(SheetName).Activate
    ActiveSheet.ChartObjects(ChartNumber).Select
    If PasteChartLink = True Then
    'Copy & Paste Chart Linked
    ActiveChart.ChartArea.Copy
    ppSlide.Shapes.PasteSpecial(link:=True).Select
    Else
    'Copy & Paste Chart Not Linked
    ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
    ppSlide.Shapes.Paste.Select
    End If
    End If
    
    'Center pasted object in the slide
    'ppApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    'ppApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    
    AppActivate ("Microsoft PowerPoint")
    Set ppSlide = Nothing
    Set ppApp = Nothing
    
    End Sub
    I need a macro which calls this particular macro 48 times and copies a different range of data each time depending on the sheet name. In other words, I need to vary SheetName and RangeName each time I call Copy_Paste_to_Powerpoint. Please help me out with this.

    Thanks,
    Amid.

  4. #4
    Registered User
    Join Date
    07-14-2009
    Location
    Ougadougou, Burkina Faso
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Copy data from excel sheet to powerpoint

    Hi,

    Regarding my previous post, I have decided to use the switch statement to select different sheets and select a range for each sheet to paste into the powerpoint. But I cant get a hang of the syntax that I have to use here. Can you please help me out with this?

    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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