+ Reply to Thread
Results 1 to 6 of 6

VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

  1. #1
    Registered User
    Join Date
    09-02-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    23

    VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    Hi everyone!

    I've the following piece of code which exports excel sheets to powerpoint. In each sheet it takes the range from cells A1 and A2 and copies that range into powerpoint.
    Now I want to add two functions, but I'am stuck to fix this, so I am hoping anyone can help me with this?

    1 - In sheets where only a table is included, the code does exactly what it's supposed to do. However in some sheets I've included a picture or a chart and these are not properly pasted in excel. (only a blank picture is copied in the powerpoint slide). Now I want to make a code that uses my input from cell "C1" to determine whether this slide needs to be pasted as an image or as a normal paste. I've tried to fix this but my code continuously gets an error. Is there any way that I can adjust this code so that I will get it working? (It's going wrong at step 5 - "PasteType")

    2 - The code now copies all worksheets, but I want it to start at sheet 7 and continue from there till the end. Thus skipping the first 6 worksheets. Does anyone have a clue how I can exclude these sheets in my VBA?



    Sub PrintPPT()
    'Step 1: Declare variables
    Dim pp As Object
    Dim PPPres As Object
    Dim PPSlide As Object
    Dim xlwksht As Worksheet
    Dim MyRange As String

    'Step 2: Open PowerPoint, add a new presentation and make visible
    Set pp = CreateObject("PowerPoint.Application")
    Set PPPres = pp.Presentations.Add
    pp.Visible = True

    'Step 3: Start the loop through each worksheet
    For Each xlwksht In ActiveWorkbook.Worksheets
    MyRange = xlwksht.Range("A1").Value & ":" & xlwksht.Range("A2").Value
    xlwksht.Range(MyRange).Copy

    'Step 4: Count slides and add new blank slide as next available slide number
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
    PPSlide.Select

    'Step 5: Paste the picture and adjust its position
    PPPres.ApplyTemplate ("C:/My location/template.potx")

    PasteType = xlwksht.Range("C1").Value
    ' Pastetype is "PasteSpecial DataType:=2" for images
    ' Pastetype is "Paste.Select" for normal

    PPSlide.Shapes.PasteType

    pp.ActiveWindow.Selection.ShapeRange.Top = 85
    pp.ActiveWindow.Selection.ShapeRange.Left = 7.2

    'Step 6: Add the title to the slide then move to next worksheet
    Next xlwksht

    'Step 7: Memory Cleanup
    pp.Activate
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set pp = Nothing

    End Sub

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    I would imagine it errors at this

    Please Login or Register  to view this content.
    PPSlide.Shapes.PasteType 'it will error here
    technically it would appear PPSlide.Shape.2

    you will probably need something like

    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    09-02-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    Thanks for your help Sean! That worked as perfectly as I had hoped!
    Do you maybe have a solution for my second question as well regarding the skipping of the first 6 excel sheets?

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    Try something like this maybe

    just change the sheet names for the ones you don't want to run the code on

    Please Login or Register  to view this content.
    you can also use the index number providing they are in the correct order
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-02-2009
    Location
    Amsterdam
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    Hi Sean, thanks again for your help, however this time I can't get either of them working. I've added your code in my step 3

    'Step 3:
    For Each xlwksht In ActiveWorkbook.Worksheets
    If xlwksht.Name = "Sheet1" Then
    Else
    MyRange = xlwksht.Range("A1").Value & ":" & xlwksht.Range("A2").Value
    xlwksht.Range(MyRange).Copy
    End If
    Next

    But if I try this, the program gives an error in step 7 "Next without For".
    If I leave the "next" out it gives an error on step 5..

    Do you maybe know what I am doing wrong?

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: VBA Excel - Powerpoint export - Dynamically copy as Images or Tables

    You probably have the end if in the wrong place

    try this

    Please Login or Register  to view this content.

+ 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. Copy data from Excel to PowerPoint slides/tables
    By RareNasturtium in forum Excel General
    Replies: 2
    Last Post: 06-07-2016, 02:22 PM
  2. VBA copy multiple excel ranges and paste as linked tables to Powerpoint
    By geniapli in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2016, 01:27 PM
  3. How to Export Texts in Powerpoint Tables into Excel
    By excelismagic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2016, 02:14 PM
  4. How to export images in comments from Excel to Word or Powerpoint using VBA Question?
    By Vladmir1111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-29-2015, 07:01 PM
  5. Excel to Powerpoint copy images
    By gsashwin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2014, 06:33 AM
  6. Copy pasting tables from Excel to Powerpoint
    By jsohng in forum Excel General
    Replies: 1
    Last Post: 12-10-2009, 05:29 PM
  7. Replies: 0
    Last Post: 05-14-2008, 04:16 AM

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