TyThompson
New Member
- Joined
- Nov 14, 2017
- Messages
- 1
Hi,
Thank you for taking the time to look at this. I really appreciate it.
I've inserted the code I used from TheSpreadsheetGuru below (I only changed the worksheet and the ranges). It all worked perfectly, initially. But then I changed the range to include columns E through X (not just through V that I had at first), and all of a sudden the code still copy and pastes but doesn't take the whole selection. It gets cut off from the right and from the bottom. I autofit the height for column X before running the macro so it would include the sentences in column X--and I am wondering if that could be a potential issue? Some of the values in X make the selection really tall.
I've included a screenshot of my first copy and paste selection--I am filtering rows, but that did not seem to be an issue initially. It was only after I extended the range to include the commentary column X.
[/FONT]
https://postimg.org/image/hi02ai0zb/
Thank you for taking the time to look at this. I really appreciate it.
I've inserted the code I used from TheSpreadsheetGuru below (I only changed the worksheet and the ranges). It all worked perfectly, initially. But then I changed the range to include columns E through X (not just through V that I had at first), and all of a sudden the code still copy and pastes but doesn't take the whole selection. It gets cut off from the right and from the bottom. I autofit the height for column X before running the macro so it would include the sentences in column X--and I am wondering if that could be a potential issue? Some of the values in X make the selection really tall.
I've included a screenshot of my first copy and paste selection--I am filtering rows, but that did not seem to be an issue initially. It was only after I extended the range to include the commentary column X.
Rich (BB code):
[FONT="]Sub[/FONT][FONT="] PasteMultipleSlides()[/FONT]
[FONT="]'PURPOSE: Copy Excel Ranges and Paste them into the Active PowerPoint presentation slides[/FONT]
[FONT="]'SOURCE: www.TheSpreadsheetGuru.com[/FONT]
[FONT="]Dim[/FONT][FONT="] myPresentation [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Object[/FONT]
[FONT="]Dim[/FONT][FONT="] mySlide [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Object[/FONT]
[FONT="]Dim[/FONT][FONT="] PowerPointApp [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Object[/FONT]
[FONT="]Dim[/FONT][FONT="] shp [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Object[/FONT]
[FONT="]Dim[/FONT][FONT="] MySlideArray [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Variant[/FONT]
[FONT="]Dim[/FONT][FONT="] MyRangeArray [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Variant[/FONT]
[FONT="]Dim[/FONT][FONT="] x [/FONT][FONT="]As[/FONT][FONT="] [/FONT][FONT="]Long[/FONT]
[FONT="]'Create an Instance of PowerPoint[/FONT]
[FONT="] [/FONT][FONT="]On[/FONT][FONT="] [/FONT][FONT="]Error[/FONT][FONT="] [/FONT][FONT="]Resume[/FONT][FONT="] [/FONT][FONT="]Next[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]'Is PowerPoint already opened?[/FONT]
[FONT="] [/FONT][FONT="]Set[/FONT][FONT="] PowerPointApp = GetObject(class:="PowerPoint.Application")[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]'Clear the error between errors[/FONT]
[FONT="] Err.Clear[/FONT]
[FONT="] [/FONT][FONT="]'If PowerPoint is not already open then Exit[/FONT]
[FONT="] [/FONT][FONT="]If[/FONT][FONT="] PowerPointApp [/FONT][FONT="]Is[/FONT][FONT="] [/FONT][FONT="]Nothing[/FONT][FONT="] [/FONT][FONT="]Then[/FONT]
[FONT="] MsgBox "PowerPoint Presentation is not open, aborting."[/FONT]
[FONT="] [/FONT][FONT="]Exit[/FONT][FONT="] [/FONT][FONT="]Sub[/FONT]
[FONT="] [/FONT][FONT="]End[/FONT][FONT="] [/FONT][FONT="]If[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]'Handle if the PowerPoint Application is not found[/FONT]
[FONT="] [/FONT][FONT="]If[/FONT][FONT="] Err.Number = 429 [/FONT][FONT="]Then[/FONT]
[FONT="] MsgBox "PowerPoint could not be found, aborting."[/FONT]
[FONT="] [/FONT][FONT="]Exit[/FONT][FONT="] [/FONT][FONT="]Sub[/FONT]
[FONT="] [/FONT][FONT="]End[/FONT][FONT="] [/FONT][FONT="]If[/FONT]
[FONT="] [/FONT][FONT="]On[/FONT][FONT="] [/FONT][FONT="]Error[/FONT][FONT="] [/FONT][FONT="]GoTo[/FONT][FONT="] 0[/FONT]
[FONT="] [/FONT]
[FONT="]'Make PowerPoint Visible and Active[/FONT]
[FONT="] PowerPointApp.ActiveWindow.Panes(2).Activate[/FONT]
[FONT="] [/FONT]
[FONT="]'Create a New Presentation[/FONT]
[FONT="] [/FONT][FONT="]Set[/FONT][FONT="] myPresentation = PowerPointApp.ActivePresentation[/FONT]
[FONT="]'List of PPT Slides to Paste to[/FONT]
[FONT="] MySlideArray = Array(2, 3, 4)[/FONT]
[FONT="]'List of Excel Ranges to Copy from[/FONT]
[FONT="] [/FONT]MyRangeArray = Array(Sheet25.Range("E5:X33"), Sheet25.Range("E38:X66"), _ Sheet25.Range("E71:X99"))
[FONT="]'Loop through Array data[/FONT]
[FONT="] [/FONT][FONT="]For[/FONT][FONT="] x = [/FONT][FONT="]LBound[/FONT][FONT="](MySlideArray) [/FONT][FONT="]To[/FONT][FONT="] [/FONT][FONT="]UBound[/FONT][FONT="](MySlideArray)[/FONT]
[FONT="] [/FONT][FONT="]'Copy Excel Range[/FONT]
[FONT="] MyRangeArray(x).Copy[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]'Paste to PowerPoint and position[/FONT]
[FONT="] [/FONT][FONT="]On[/FONT][FONT="] [/FONT][FONT="]Error[/FONT][FONT="] [/FONT][FONT="]Resume[/FONT][FONT="] [/FONT][FONT="]Next[/FONT]
[FONT="] [/FONT][FONT="]Set[/FONT][FONT="] shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) [/FONT][FONT="]'Excel 2007-2010[/FONT]
[FONT="] [/FONT][FONT="]Set[/FONT][FONT="] shp = PowerPointApp.ActiveWindow.Selection.ShapeRange [/FONT][FONT="]'Excel 2013[/FONT]
[FONT="] [/FONT][FONT="]On[/FONT][FONT="] [/FONT][FONT="]Error[/FONT][FONT="] [/FONT][FONT="]GoTo[/FONT][FONT="] 0[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]'Center Object[/FONT]
[FONT="] [/FONT][FONT="]With[/FONT][FONT="] myPresentation.PageSetup[/FONT]
[FONT="] shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)[/FONT]
[FONT="] shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)[/FONT]
[FONT="] [/FONT][FONT="]End[/FONT][FONT="] [/FONT][FONT="]With[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT][FONT="]Next[/FONT][FONT="] x[/FONT]
[FONT="]'Transfer Complete[/FONT]
[FONT="] Application.CutCopyMode = [/FONT][FONT="]False[/FONT]
[FONT="] ThisWorkbook.Activate[/FONT]
[FONT="] MsgBox "Complete!"[/FONT]
[FONT="]End[/FONT][FONT="] [/FONT][FONT="]Sub
https://postimg.org/image/hi02ai0zb/