Hello everyone,
I have Microsoft Office 2003 and Windows Vista. I'm a relative VBA newbie, but I have been experimenting with copying individual cells in Excel to individual PowerPoint slides via a macro. No matter how many individual cells I copy to individual slides, and no matter what order the copying takes place, there seems to be a limit of 248 cells that are copied. It is not dependent on how much text is in each copied cell. The macro pretends to copy each cell to a new slide (I can see PowerPoint creating a new slide for every copied cell), but when I go to look at the finished PowerPoint file that has been created, only 248 of the slides actually contain the pasted material and the rest are blank.
Here is the code I am running:
I would be very grateful for some help on this!
ML
I have Microsoft Office 2003 and Windows Vista. I'm a relative VBA newbie, but I have been experimenting with copying individual cells in Excel to individual PowerPoint slides via a macro. No matter how many individual cells I copy to individual slides, and no matter what order the copying takes place, there seems to be a limit of 248 cells that are copied. It is not dependent on how much text is in each copied cell. The macro pretends to copy each cell to a new slide (I can see PowerPoint creating a new slide for every copied cell), but when I go to look at the finished PowerPoint file that has been created, only 248 of the slides actually contain the pasted material and the rest are blank.
Here is the code I am running:
Code:
Sub Pastetoppt ()
' Start PowerPoint.
Dim ppApp As PowerPoint.Application
Set ppApp = CreateObject("Powerpoint.Application")
' Make it visible.
ppApp.Visible = True
' Add a new presentation.
Dim ppPres As PowerPoint.Presentation
Set ppPres = ppApp.Presentations.Add(msoTrue)
' Add new slide.
Dim ppSlide As PowerPoint.Slide
Set ppSlide = ppPres.Slides.Add(Index:=1, Layout:=ppLayoutText)
' Find coordinates of last cell in range.
Dim lastrow As Integer
Dim lastcol As Integer
lastrow = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).row
lastcol = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Column
Dim rng As Range
Dim row As Range
Dim cell As Range
Set rng = Range(Cells(1, 1), Cells(lastrow, lastcol))
For Each row In rng.Rows
For Each cell In row.Cells
cell.Select
Selection.Copy
Dim ppSlide2 As PowerPoint.Slide
Dim x As Integer
x = ppPres.Slides.Count
Set ppSlide2 = ppPres.Slides.Add(Index:=x, Layout:=ppLayoutText)
ppApp.ActivePresentation.Slides(x).Select
ppApp.ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
ppApp.ActiveWindow.Selection.TextRange.Paste
Next cell
Next row
End Sub
ML