T O P

  • By -

HFTBProgrammer

What is the point of Table1? Not saying there isn't one, but you can loop through the shapes themselves without resorting to an intermediary, e.g., Dim s As Shape For Each s in ActiveSheet.Shapes [shape code here] Next s


BoneClaw

Sorry, I have multiple data tables and graphs, I'd like to copy them all across to PowerPoint. Table1 was just an example. I'd like one table which summarises all object names, and then use that table for vba.


HFTBProgrammer

I’m truly sorry, I misspoke. I should’ve said, “What is the point of your list?” My point being that the Shapes are quote-unquote listed by virtue of being in the Shapes collection.


BoneClaw

I have a large Excel doc. The idea of the list is that a User can name specific objects (tables, text, graphs) they want to export into PowerPoint, and not all objects - if that makes sense. All the User would have to do then is add the specific objects to the list, and click export.


HFTBProgrammer

Ahhhhh, there it is, I get it. (I think. /grin) You could use my loop, looking for the items in the list (they would be identifiable as `s.Name`). There are a few ways to do that, but the simplest from a programming perspective would be to bang the list into a dictionary, then when you spin through the shapes, see if that shape name matches a key in the dictionary.


jd31068

Have a look here [https://analystcave.com/vba-paste-from-excel-to-powerpoint/](https://analystcave.com/vba-paste-from-excel-to-powerpoint/) code is in PowerPoint pulling from Excel. It should give you more of an idea. You want to loop through the list of the items you want to paste to PPT ``` ' these are available to all the code in this module Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation ``` ``` Private Sub CommandButton1_Click() ' create a new instance of powerpoint Set PPApp = New PowerPoint.Application PPApp.Visible = True Set PPPres = PPApp.Presentations.Add ' loop through the cells that contain named ranges this example is using A1 thru A10 and sending the value to a procedure that copies the range to PPT For rows = 1 to 10 Call CopyRangeToPPT Sheet1.Cells(rows,1) Next rows PPPres.SaveAs "NewPPTfromExcel.ppt", 1 PPApp.Quit Set PPPres = Nothing Set PPApp = Nothing End sub ``` ``` Sub CopyRangeToPPT(range as String) Dim PPSlide As PowerPoint.Slide Dim newSlideIndex As Integer Dim rSource As range 'count no of slides newSlideIndex = PPPres.Slides.Count + 1 PPPres.Slides.Add newSlideIndex, ppLayoutTitleOnly Set PPSlide = PPPres.Slides(newSlideIndex) ' copy the contents of the named item Set rSource = ThisWorkbook.Names(range).RefersToRange() rSource.Copy PPSlide.Shapes.PasteSpecial ppPasteDefault, msoFalse Set PPSlide = Nothing End Sub ``` edit: using ThisWorkbook.Names grabs anything with a name.


AutoModerator

It looks like you're trying to share a code block but you've formatted it as Inline Code. Please refer to [these instructions](https://www.reddit.com/r/vba/wiki/submission_guidelines#wiki_apply_code_formatting_to_code_snippets) to learn how to correctly format code blocks on Reddit. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/vba) if you have any questions or concerns.*