I'm trying to replicate the effect of manually copying a range in Excel and pasting it into Powerpoint in Office 2007. From what I can gather, it's creating a shape with the type of msoTable. I can't seem to replicate this behavior through VBA. I think I've got all the hard stuff done, but can't figure out the easy part.
I've looked though the forums and found a bunch of solutions that don't do exactly what I need. I don't want to copypicture the range as an image - I don't want to link the data though OLE objects - I'd prefer not to dynamically recreate the table by looping through all the cells in the range and getting the values (Since I don't want to have to worry about formatting).
Sub CreatePowerPoint()
' Create an instance of PowerPoint.
Dim oPPTApp As PowerPoint.Application
Set oPPTApp = New PowerPoint.Application
' Open the Excel workbook containing the worksheet with the chart data.
Dim oWorkbook As Workbook
Set oWorkbook = ActiveWorkbook
oPPTApp.Visible = msoTrue
oPPTApp.WindowState = ppWindowMinimized
' Create a PowerPoint presentation.
Set pptPresentation = oPPTApp.Presentations.Open("C:\BenchmarkingTemplate.ppt")
Dim pptSlide As Slide
Set pptSlide = _
pptPresentation.Slides.Add(pptPresentation.Slides.Count + 1, ppLayoutTitleOnly)
Sheets("Cht1").Activate
Range(Cells(36, 1), Cells(38, 7)).Select
Selection.Copy
'This is where it crashes
Set ShapeRange = pptSlide.Shapes.Paste
ShapeRange.Left = 318
ShapeRange.Top = 96
ShapeRange.Height = 240
ShapeRange.Width = 390
' Save the presentation.
sFileName = Application.GetSaveAsFilename
pptPresentation.SaveAs (sFileName)
' Release the PowerPoint slide object.
Set ShapeRange = Nothing
Set pptSlide = Nothing
' Close and release the Presentation object.
If Not pptPresentation Is Nothing Then
pptPresentation.Close
Set pptPresentation = Nothing
End If
oPPTApp.Presentations.Open (sFileName)
oPPTApp.WindowState = ppWindowMaximized
End Sub
It crashes with: "Shapes (unkown member): Invalid request. Clipboard is empty or contains data which may not be pasted here."
Any help on how to mimic the effect of copying/pasting manually would be greatly appreciated!
I've looked though the forums and found a bunch of solutions that don't do exactly what I need. I don't want to copypicture the range as an image - I don't want to link the data though OLE objects - I'd prefer not to dynamically recreate the table by looping through all the cells in the range and getting the values (Since I don't want to have to worry about formatting).
Sub CreatePowerPoint()
' Create an instance of PowerPoint.
Dim oPPTApp As PowerPoint.Application
Set oPPTApp = New PowerPoint.Application
' Open the Excel workbook containing the worksheet with the chart data.
Dim oWorkbook As Workbook
Set oWorkbook = ActiveWorkbook
oPPTApp.Visible = msoTrue
oPPTApp.WindowState = ppWindowMinimized
' Create a PowerPoint presentation.
Set pptPresentation = oPPTApp.Presentations.Open("C:\BenchmarkingTemplate.ppt")
Dim pptSlide As Slide
Set pptSlide = _
pptPresentation.Slides.Add(pptPresentation.Slides.Count + 1, ppLayoutTitleOnly)
Sheets("Cht1").Activate
Range(Cells(36, 1), Cells(38, 7)).Select
Selection.Copy
'This is where it crashes
Set ShapeRange = pptSlide.Shapes.Paste
ShapeRange.Left = 318
ShapeRange.Top = 96
ShapeRange.Height = 240
ShapeRange.Width = 390
' Save the presentation.
sFileName = Application.GetSaveAsFilename
pptPresentation.SaveAs (sFileName)
' Release the PowerPoint slide object.
Set ShapeRange = Nothing
Set pptSlide = Nothing
' Close and release the Presentation object.
If Not pptPresentation Is Nothing Then
pptPresentation.Close
Set pptPresentation = Nothing
End If
oPPTApp.Presentations.Open (sFileName)
oPPTApp.WindowState = ppWindowMaximized
End Sub
It crashes with: "Shapes (unkown member): Invalid request. Clipboard is empty or contains data which may not be pasted here."
Any help on how to mimic the effect of copying/pasting manually would be greatly appreciated!