Hi,
after reading several threads and posts from Andy Pope, I managed to build a macro that modifies my table in Excel as I intended and then copies it into a defined slide of a specific ppt. So far I am happy.
On that slide is already a empty textbox. I now want to align the table's upper left corner with that of the textbox and then - with aspect ratio locked - make the table the same width as the text box.
I recorded a macro in ppt that does exactly that. I then copy/pasted the code into my Excel macro, but it doesn't work there anymore.
This is the code of the combined macro:
Code
Sub test4()
'this part copies the table in a new worksheet
'and deletes all rows that have not the value '1' in column 's'
ActiveSheet.Copy Before:=ActiveSheet
Application.ScreenUpdating = False
On Error Resume Next
Dim ir As Long, mrows As Long, lastcell As Range
Set lastcell = Cells.SpecialCells(xlLastCell)
mrows = lastcell.Row
'Note rows are deleted from the bottom going up
For ir = mrows To 1 Step -1
If Len(Trim(Range("s" & ir).Value)) = 0 Then
Rows(ir).Delete Shift:=xlUp
End If
Next
'this part copies again the table in a new worksheet and then
'deletes all columns that have not the value '1' in row '2'
ActiveSheet.Copy Before:=ActiveSheet
Dim myrange, mycell As Range
mycol = Sheets("Presentation outputs (3)").Range("A2", Range("IV2").End(xlToLeft)).Columns.Count
For i = (mycol + 1) To 1 Step -1
If Sheets("Presentation outputs (3)").Range("A2").Offset(0, i - 1) = 0 Then
Sheets("Presentation outputs (3)").Range("A2").Offset(0, i - 1).EntireColumn.Delete
End If
Next i
'this part opens the presentation 'lalala.ppt'
'which is in the same folder as the spreadsheet
'and copies the table on slide number 2
Dim objPPT As Object
Dim objPrs As Object
ActiveSheet.Range("A5:N29").CopyPicture
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
objPPT.presentations.Open ThisWorkbook.Path & "\lalala.ppt"
objPPT.presentations(1).slides(2).Select
objPPT.ActiveWindow.ViewType = 1 'ppViewSlide
objPPT.ActiveWindow.View.Paste
'the following part shall allign the top left corner of the table
'with that of a text box which is already on slide number 2,
'and then widen the table that it has the same width as the textbox
'with aspect ratio locked
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 0.65, msoFalse, msoScaleFromTopLeft
.ScaleHeight 0.65, msoFalse, msoScaleFromTopLeft
End With
With ActiveWindow.Selection.ShapeRange
.IncrementLeft 121.5
.IncrementTop 39#
End With
ActiveWindow.Selection.SlideRange.Shapes.Range(Array("Picture 8", "Rectangle 3")).Select
ActiveWindow.Selection.ShapeRange.Align msoAlignLefts, False
ActiveWindow.Selection.ShapeRange.Align msoAlignTops, False
ActiveWindow.Selection.Unselect
ActiveWindow.Selection.SlideRange.Shapes("Picture 8").Select
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.34, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.34, msoFalse, msoScaleFromTopLeft
End With
objPPT.presentations(1).Save
objPPT.Quit
Set objPrs = Nothing
Set objPPT = Nothing
Application.ScreenUpdating = True
End Sub
Display More
Can anyone help? Has ppt a different macro language than Excel? Where did I do a mistake?
Thanks.