Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Public Sub tableArray()
  2.  
  3. 'Timer start
  4. Dim StartTime As Double
  5. Dim SecondsElapsed As Double
  6. StartTime = Timer
  7.  
  8. 'Create variables
  9. Dim xlApp As Excel.Application
  10. Dim xlWB As Excel.Workbook
  11. Dim ShRef As Excel.Worksheet
  12. Dim pptPres As Object
  13. Dim colNumb As Long
  14. Dim rowNumb As Long
  15. Dim i As Long
  16. Dim myShape As Object
  17.  
  18. Excel.Application.DisplayAlerts = False
  19.  
  20. ' Create new excel instance and open relevant workbook
  21. Set xlApp = New Excel.Application
  22. 'xlApp.Visible = True 'Make Excel visible
  23. Set xlWB = xlApp.Workbooks.Open("filePath", True, False, , , , True, Notify:=False) 'Open relevant workbook
  24. If xlWB Is Nothing Then ' may not need this if statement. check later.
  25. MsgBox ("Error retrieving file, Check file path")
  26. Exit Sub
  27. End If
  28.  
  29. 'Find # of iq's in workbook
  30. Set ShRef = xlWB.Worksheets("Sheet1")
  31. colNumb = ShRef.Cells(1, ShRef.Columns.Count).End(xlToLeft).Column
  32. rowNumb = ShRef.Cells(ShRef.Rows.Count, 1).End(xlUp).Row
  33.  
  34. Dim IQRef() As String
  35. Dim iCol As Long
  36. Dim iRow As Long
  37.  
  38. ReDim IQRef(1 To rowNumb, 2 To colNumb)
  39. ' capture IQ refs locally
  40. For iRow = 1 To rowNumb
  41. For iCol = 2 To colNumb
  42. IQRef(iRow, iCol) = ShRef.Cells(iRow, iCol).Value
  43. Next iCol
  44. Next iRow
  45. 'Make pptPres the ppt active
  46. Set pptPres = PowerPoint.ActivePresentation
  47.  
  48. 'Create variables for the slide loop
  49. Dim pptSlide As Slide
  50. Dim unionVariable
  51.  
  52. Set unionVariable = xlApp.Union(IQRef(1, 2), IQRef(2, 2), IQRef(3, 2), IQRef(4, 2), IQRef(1, 7), IQRef(2, 7), IQRef(3, 7), IQRef(4, 7))
  53.  
  54. For Each pptSlide In pptPres.Slides
  55.  
  56. ' Copy table
  57. unionVariable.Copy ' copy unioneVariable that should be a table
  58.  
  59. ActiveWindow.ViewType = ppViewNormal
  60. ActiveWindow.Panes(2).Activate
  61.  
  62. Set myShape = pptSlide.Shapes.PasteSpecial(DataType:=ppPasteHTML, Link:=msoFalse) 'Should paste unionVariable's table
  63.  
  64. 'Set position:
  65. myShape.Left = -200
  66. myShape.Top = 150 + i
  67. i = i + 150
  68.  
  69. Next pptSlide
  70.  
  71. xlWB.Close
  72. xlApp.Quit
  73.  
  74. Excel.Application.DisplayAlerts = True
  75.  
  76. 'End Timer
  77. SecondsElapsed = Round(Timer - StartTime, 2)
  78. MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
  79.  
  80. End Sub
Add Comment
Please, Sign In to add comment