zanhlll
02-05-2013, 08:20 PM
I am writing VBA to copy & paste tables in excel to powerpoint.
Executed from excel, the code is able to create new ppt slide (with caption only), paste the excel as bitmap, and add a textbox with some sample text.
However when the code adds the second slide, the textbox (reference by tbox in the code below) will be lost. If I create two textboxes , both will be lost.
What is the correct way to create the textbox and add new slide to prevent this from happening?
-----
For count = 1 To tables
' select the Nth KPI table
XLApp.Selection.CurrentRegion.Select
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
' PROBLEM the next line, when executed on the second pass (count = 2),
' somehow causes the textbox created on the previous slide to disappear.
Set PPSlide = PPPres.Slides.Add(count + 1, ppLayoutTitleOnly) 'add 1 to account for cover page.
PPSlide.Select ' have to select slide / make visible else paste.select crashes (WHY?)
' add text box at bottom of slide
Set tbox = PPSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 500, 700, 250)
tbox.TextFrame.TextRange.Text = "<1 - Enter Text Here>"
' resize and position picture
shp = PPSlide.Shapes.Paste.Name
With PPSlide.Shapes(shp)
.Top = 70
.Left = 10
.Width = 700
End With
' Junp to end of current table
XLApp.Selection.End(xlDown).Select
If (count <> tables) Then
' Junp to start of next KPI table
XLApp.Selection.End(xlDown).Select
End If
Next count
Executed from excel, the code is able to create new ppt slide (with caption only), paste the excel as bitmap, and add a textbox with some sample text.
However when the code adds the second slide, the textbox (reference by tbox in the code below) will be lost. If I create two textboxes , both will be lost.
What is the correct way to create the textbox and add new slide to prevent this from happening?
-----
For count = 1 To tables
' select the Nth KPI table
XLApp.Selection.CurrentRegion.Select
XLApp.Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
' PROBLEM the next line, when executed on the second pass (count = 2),
' somehow causes the textbox created on the previous slide to disappear.
Set PPSlide = PPPres.Slides.Add(count + 1, ppLayoutTitleOnly) 'add 1 to account for cover page.
PPSlide.Select ' have to select slide / make visible else paste.select crashes (WHY?)
' add text box at bottom of slide
Set tbox = PPSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 500, 700, 250)
tbox.TextFrame.TextRange.Text = "<1 - Enter Text Here>"
' resize and position picture
shp = PPSlide.Shapes.Paste.Name
With PPSlide.Shapes(shp)
.Top = 70
.Left = 10
.Width = 700
End With
' Junp to end of current table
XLApp.Selection.End(xlDown).Select
If (count <> tables) Then
' Junp to start of next KPI table
XLApp.Selection.End(xlDown).Select
End If
Next count