Hello,
I have PowerPoint 2007 slides that contain tables, and I'm working on a macro that will transfer that data to Excel 2007. I don't want to just do a straight copy/paste, because I need to be able to manipulate the data as it is imported. The tables are all 5 columns wide, but vary in height. I get new tables in on a weekly basis, so would like to have code that can automate the process of tranferring this data from PowerPoint to Excel. So far, below is what I have come up with, but I'm getting a "Run-time error '438': Object doesn't support this property or method". I have Excel open, and I have selected the Excel object library in the VBE references. Any help/insight/direction/suggestions would be greatly appreciated. I feel like I'm coming to the end of my (admittedly very limited) coding capabilities.
Thanks,
Ian
I have PowerPoint 2007 slides that contain tables, and I'm working on a macro that will transfer that data to Excel 2007. I don't want to just do a straight copy/paste, because I need to be able to manipulate the data as it is imported. The tables are all 5 columns wide, but vary in height. I get new tables in on a weekly basis, so would like to have code that can automate the process of tranferring this data from PowerPoint to Excel. So far, below is what I have come up with, but I'm getting a "Run-time error '438': Object doesn't support this property or method". I have Excel open, and I have selected the Excel object library in the VBE references. Any help/insight/direction/suggestions would be greatly appreciated. I feel like I'm coming to the end of my (admittedly very limited) coding capabilities.
Thanks,
Ian
Code:
Sub DataTransfer()
Dim tb As Table
Dim shp As Shape, tg$, i%
Dim kid As String
Dim start As String
Dim target As String
Dim actual As String
Dim status As String
Dim statForm As String
Dim rowNum As Integer
Dim colNum As Integer
Dim colCount As Integer
Dim rowCount As Integer
Dim exApp As Excel.Application
For i = 1 To ActivePresentation.Slides.Count
tg = ""
For Each shp In ActivePresentation.Slides(i).Shapes
If shp.HasTable Then
tg = shp.Name 'finds first table
Exit For
End If
Next
Select Case tg
Case Is = ""
MsgBox "Slide " & i & " has no tables", vbCritical
Case Else
Set tb = ActivePresentation.Slides(i).Shapes(tg).Table
colNum = 1
With tb
colCount = .Columns.Count
rowCount = .Rows.Count
For rowNum = 1 To .Rows.Count
kid = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
colNum = colNum + 1
start = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
colNum = colNum + 1
target = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
colNum = colNum + 1
actual = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
colNum = colNum + 1
status = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
statForm = (.Cell(rowNum, colNum).Shape.TextFrame.TextRange)
colNum = 1
Set exApp = GetObject(, "Excel.Application")
With exApp.Selection
.ActiveCell.Value = kid
.ActiveCell.Offset(0, 1).Select
.ActiveCell.Value = start
.ActiveCell.Offset(0, 1).Select
.ActiveCell.Value = target
.ActiveCell.Offset(0, 1).Select
.ActiveCell.Value = actual
.ActiveCell.Offset(0, 1).Select
With Selection
.Value = status
.Interior.Color = statForm
End With
.ActiveCell.Offset(1, -4).Select
End With
Next rowNum
End With
End Select
Next
End Sub