Results 1 to 5 of 5

Thread: Manipulating an Excel Table from within a PPT Presentation

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    14

    Manipulating an Excel Table from within a PPT Presentation

    I am trying to manipulate an excel table from within a powerpoint presentation using macros. What I want to be able to do is to change cell colors, copy and paste rows and columns (basically shift rows up and down, and shift columns left and right) and a few other things. But I'm a novice with macros and I keep running into problems.

    What I've done is first make a macro manipulating the table from inside excel to test it and then I tried using that macro in the ppt with the "addresses" changed.

    Well, to have a look at the excel file with the macro working the way I want it, download this file: sample.xls.

    And sample.ppt is trying to do the same thing as the macro in the above table file but from inside a powerpoint presentation (with a table embeded as an object)

    Because the whole macro didn't work inside powerpoint, I split parts of the code to see if it worked by itself. I managed to be able to "target" a particular cell inside the embeded table and change the contents. However, changing the cell color does not seem to work. Nor copying and pasting.

    For instance, this works:

    Code:
    ActivePresentation.Slides(1).Shapes("Table").OLEFormat.Object.Application.Workbooks(1).Worksheets(1).Cells(2, 4) = "HA"

    But this doesn't:

    Code:
    With ActivePresentation.Slides(1).Shapes("Table").OLEFormat.Object.Application.Workbooks(1).Worksheets(1).Cells(2, 5).Interior
            .ColorIndex = 4
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            End With
    Well, I'm quite stumped and I would really appreciate some help.

    Thanks!


    ---- Update ----

    Someone suggested that I use this revised code:

    Code:
    Sub Sort() 
        Dim i, j, jtmp, itmp 
         
        With ActivePresentation.Slides(1).Shapes("Table").OLEFormat.Object.Application.Workbooks(1).Worksheets(1) 
            For i = 2 To 28 
                For j = 3 To 29 
                    If .Cells(i, j) = "x" Then 
                        If j > i Then 
                             
                            With .Cells(i, j).Interior 
                                .ColorIndex = 4 
                                .Pattern = xlSolid 
                                .PatternColorIndex = xlAutomatic 
                            End With 
                             
                            Sleep (500) 
                             
                            With .Cells(i, j).Interior 
                                .ColorIndex = xlNone 
                                .Pattern = xlNone 
                                .PatternColorIndex = xlNone 
                                 
                                .Cells(j, 1).EntireRow.Select 
                                .Selection.Insert Shift:=xlDown 
                                .Cells(i, 1).EntireRow.Select 
                                .Selection.Cut 
                                .Cells(j, 1).EntireRow.Select 
                                .Paste 
                                .Cells(i, 1).EntireRow.Select 
                                .Selection.Delete Shift:=xlUp 
                                jtmp = j + 1 
                                .Cells(1, jtmp).EntireColumn.Select 
                                .Selection.Insert Shift:=xlToRight 
                                itmp = i + 1 
                                .Cells(1, itmp).EntireColumn.Select 
                                .Selection.Cut 
                                .Cells(1, jtmp).EntireColumn.Select 
                                .Paste 
                                .Cells(1, itmp).EntireColumn.Select 
                                .Selection.Delete Shift:=xlToLeft 
                            End With 
                        End If 
                    End If 
                Next j 
            Next i 
             
        End With 
         
    End Sub
    But I get a "Run-time error 438: object doesn't support this property or method" error for the following line:

    Code:
    .Cells(j, 1).EntireRow.Select
    Does it by any chance have anything to do with references? Not exactly sure what references are but I have enabled "Microsoft Excel 11.0 Object Library".

    And I would also like to ask why there is such a susceptible delay when a macro is triggered by clicking on the button? Why isn't it as instantaneous as in from within excel? And more importantly, is it possible to reduce this delay?
    Last edited by epak; May 26th, 2006 at 11:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width