+ Reply to Thread
Results 1 to 3 of 3

copy a chart and table from a worksheet to slide no. 2

  1. #1
    Registered User
    Join Date
    02-13-2017
    Location
    india
    MS-Off Ver
    20113
    Posts
    1

    copy a chart and table from a worksheet to slide no. 2

    I have two issues in this code. This code works fine sometimes but attimes gives the following error: Run Time Error - 2147188160 (80048240) Shapes (unknown member): Invalid Request. Clipboard is empty or contains data which may not be pasted here. It is coming on the below mentioned code When I am trying to paste the range/table.

    pres.Slides(2).Shapes.Paste
    Second Question: now the chart is getting copied in the powerpoint second thing which I want to know if I need to position it. In case there was no specific slide (slide 2) where I would like to put the chart at top left corner then t how shud I modify the below code: – preslide.Shapes.PasteSpecial (ppPasteHTML)

    With preslide.Shapes(preslide.Shapes.Count)

    .Top = 65 .Left = 72 .Width = 700

    Sub latestppu()
    Dim pptapp As PowerPoint.Application
    Dim pres As PowerPoint.Presentation
    Dim preslide As PowerPoint.Slide
    Dim shapepp As PowerPoint.Shape
    Dim exappli As Excel.Application
    Dim exworkb As Workbook
    Dim rng As Range
    Dim myshape As Object
    Dim x As Integer
    x = 1
    Dim mychart As ChartObject
    Dim activechart As ChartObject
    Dim R As Integer
    Dim G As Integer
    Dim B As Integer

    'Open powerpoint application -
    Set exappli = New Excel.Application
    exappli.Visible = True

    'activate powerpoint application
    Set pptapp = New PowerPoint.Application
    pptapp.Visible = True
    pptapp.Activate

    'open the excel you wish to use
    Set exworkb = exappli.Workbooks.Open("C:\Users\as\Desktop\Macro\Reference Sheet.xlsm")

    'open the presentation you wish to use
    Set pres = pptapp.Presentations.Open("C:\Users\as\Desktop\Macro\PPTtemplate.pptx")
    'Add title to the first slide
    With pres.Slides(1)
    If Not .Shapes.HasTitle Then
    Set shapepp = .Shapes.AddTitle
    Else: Set shapepp = .Shapes.Title
    End If
    With shapepp
    .TextFrame.TextRange.Text = "Gulf+ Mark" & vbNewLine & "P5 Week FY17"
    .TextFrame.TextRange.Font.Name = "Arial Black"
    .TextFrame.TextRange.Font.Size = 24
    .TextEffect.FontBold = msoTrue
    .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignLeft
    End With
    End With
    'Add title to second slide
    With pres.Slides(2)
    If Not .Shapes.HasTitle Then
    Set shapepp = .Shapes.AddTitle
    Else: Set shapepp = .Shapes.Title
    End If
    With shapepp
    .TextFrame.TextRange.Text = "Gulf+ Performance"
    .TextFrame.TextRange.Font.Name = "EY Gothic Cond Demi"
    .TextFrame.TextRange.Font.Size = 22
    .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignLeft
    .TextEffect.FontBold = msoFalse
    .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
    .TextEffect.Alignment = msoTextEffectAlignmentLeft
    End With
    End With
    'add a textbox
    Set shapepp = pres.Slides(2).Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=650, Top:=75, Width:=200, Height:=50)
    With shapepp
    .TextFrame.TextRange.Text = "Other Account Performance Metrics"
    .TextFrame.TextRange.Font.Name = "EY Gothic Cond Demi"
    .TextFrame.TextRange.Font.Size = 16
    .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignRight
    .TextEffect.FontBold = msoTrue
    .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
    End With

    'Copy a table range from account summary worksheet and paste it in powerpoint slide 2:-
    'defining the range
    Set rng = exworkb.Sheets("Account Performance").Range("A1:B5")
    'Copy excel range
    rng.Copy
    'paste to powerpoint slide 2
    pres.Slides(2).Shapes.Paste
    pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignTops, msoTrue
    pptapp.ActiveWindow.Selection.ShapeRange.Top = -30
    pptapp.ActiveWindow.Selection.ShapeRange.Left = 350


    'add a textbox
    Set shapepp = pres.Slides(2).Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=600, Top:=280, Width:=200, Height:=50)
    With shapepp
    .TextFrame.TextRange.Text = "GTER by global account segment"
    .TextFrame.TextRange.Font.Name = "EY Gothic Cond Demi"
    .TextFrame.TextRange.Font.Size = 16
    .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignRight
    .TextEffect.FontBold = msoTrue
    .TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
    End With
    'defining the second chart to be copied
    Set mychart = exworkb.Sheets("Account Performance").ChartObjects(1)
    mychart.Select
    mychart.Chart.ChartArea.Copy
    pres.Slides(2).Shapes.Paste
    pptapp.ActiveWindow.Selection.ShapeRange.Align msoAlignTops, msoTrue
    pptapp.ActiveWindow.Selection.ShapeRange.Top = 2000
    pptapp.ActiveWindow.Selection.ShapeRange.Left = 350

    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello itsme2216,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: copy a chart and table from a worksheet to slide no. 2

    Hi itsme2216
    Welcome to Excel Forum
    एक्सेल फोरम में आपका स्वागत है
    This is just the Sub Forum to say hello
    Unfortunately you are posting incorrectly ( and have Possibly in your haste have not read the Rules which you agreed to on registering. This makes it difficult for the people here to help you, many of which will likely be keen to do so )

    You must start a new Thread here if you need help:

    http://www.excelforum.com/excel-general/
    or here:
    http://www.excelforum.com/excel-formulas-and-functions/
    or if you would consider a macro solution then here:
    http://www.excelforum.com/excel-programming-vba-macros/



    If you are not sure, then probably the first will do
    http://www.excelforum.com/excel-general/

    _............................................

    Please, also, if you get time, take some time before posting to read the Forum Rules here
    http://www.excelforum.com/forum-rule...rum-rules.html
    http://www.excelforum.com/forums-rules/
    http://www.excelforum.com/developmen...ml#post4519006
    http://www.excelforum.com/developmen...ml#post4532042
    It is usually worth it in the long run.

    Thanks
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

+ 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. Copying Excel table range to an existing PPT slide, pasting as TABLE, not as PICTURE
    By gurnblanston27 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2016, 04:44 PM
  2. Copy and paste entire slide as an picture into new slide
    By Alistairm88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2015, 10:29 AM
  3. Script to copy excel table in to a powerpoint slide
    By Robert110 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2014, 06:15 PM
  4. How can I add a slide bar to the top of a chart?
    By David HK in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 03-02-2013, 09:04 AM
  5. Replies: 1
    Last Post: 04-02-2012, 03:57 PM
  6. Macros to copy chart from Excel into specific PPT Slide
    By undergraduate in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-03-2010, 12:00 PM
  7. Copy Excel chart into new ppt slide
    By grantj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2006, 03:56 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