Consulting

Results 1 to 4 of 4

Thread: Copy and paste row values in a table.

  1. #1

    Copy and paste row values in a table.

    Having following code in .bas(macro).

    [vba]Set shpGrpTable = Slide.Shapes.AddTable(3, 6,18#,250, 681#, 600)

    Set grpTxtFrame = shpGrpTable.Table.Cell(1, 1).Shape.TextFrame
    grpTxtFrame.TextRange.Text = "GROUP"
    grpTxtFrame.TextRange.Font.Size = 14
    grpTxtFrame.TextRange.Font.Name = "Arial"
    grpTxtFrame.TextRange.Font.Color.RGB = 16777215
    grpTxtFrame.TextRange.Font.Bold = msoTrue
    grpTxtFrame.HorizontalAnchor = msoAnchorCenter
    grpTxtFrame.VerticalAnchor = 3

    Set prmTxtFrame = shpGrpTable.Table.Cell(2, 1).Shape.TextFrame
    prmTxtFrame.TextRange.Text = "COUNTRY"
    prmTxtFrame.TextRange.Font.Size = 14
    prmTxtFrame.TextRange.Font.Name = "Arial"
    prmTxtFrame.TextRange.Font.Color.RGB = 16777215
    prmTxtFrame.TextRange.Font.Bold = msoTrue
    prmTxtFrame.HorizontalAnchor = msoAnchorCenter
    prmTxtFrame.VerticalAnchor = 3[/vba]
    1. grpTxtFrame and prmTxtFrame are having the same properties. After creating grpTxtFrame, how to copy and paste grpTxtFrame into cell(2,1) and how to reassign value('COUNTRY) to cell(2,1).

    2. shpGrpTable is created in slide1 and how to copy this into slide2.

    Thanks in advance.
    Sharath.
    Last edited by Killian; 09-16-2005 at 02:31 AM. Reason: Formatting and added VBA tags

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi and welcome to VBAX

    All you need to do here is use a variable for the row index and run the same code twice (to set the properties) with a For... Next loop - checking which row you are on and setting the Text appropriately.
    Here's the code, which adds a table on the current slide[VBA]Dim shpGrpTable As Shape
    Dim intRowindex As Integer

    Set shpGrpTable = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex).Shapes _
    .AddTable(3, 6, 20, 100, 680, 400)

    For intRowindex = 1 To 2
    With shpGrpTable.Table.Cell(intRowindex, 1).Shape.TextFrame
    Select Case intRowindex
    Case 1
    .TextRange.Text = "GROUP"
    Case 2
    .TextRange.Text = "COLUMN"
    End Select
    .TextRange.Font.Size = 14
    .TextRange.Font.Name = "Arial"
    .TextRange.Font.Color.RGB = 16777215
    .TextRange.Font.Bold = msoTrue
    .HorizontalAnchor = msoAnchorCenter
    .VerticalAnchor = 3
    End With
    Next intRowindex[/VBA]

    You you could use another loop for the slide index if you specifically want to add the table to sildes 1 and 2
    e.g:
    [VBA]For intSlideIndex = 1 To 2
    Set shpGrpTable = ActivePresentation.Slides(intSlideIndex).Shapes.AddTable(3, 6, 20, 100, 680, 400)
    'etc...etc...
    Next intSlideIndex[/VBA]
    K :-)

  3. #3
    Thanks Killian,


    Rather than executing all these properties for each table cell
    .TextRange.Font.Size = 14
    .TextRange.Font.Name = "Arial"
    .TextRange.Font.Color.RGB = 16777215
    .TextRange.Font.Bold = msoTrue
    .HorizontalAnchor = msoAnchorCenter
    .VerticalAnchor = 3
    whether we can format first cell(1,1) and copy this cell to next cell(1,2) and set the text for this(assuming that it will grab all the properties set for this cell when we copy first cell). I think this will improve the performance (I'm guessing).



    If this improves performance then please let me know, how to copy and paste cell values.



    Please advice.


    Thanks,
    Sharath.

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi there,

    Well, you can use the PickUp and Apply methods of the shape (used when you use the format painter in the toolbar) which is what you are reffering to.
    When dealing with all the cells in a table, the performance issue won't be resolved because what takes the time (and causes lots of screen flickering) is the fact that you have to loop through all the rows - then all the cells in each row - of the table. PowerPoint's object model is not good in this respect.
    Here's some code that does it - run it on a big table and you'll see what I mean[VBA]Sub CopyFormatTableCells()

    Dim shpTable As Table
    Dim objTableRow As Row
    Dim cl As Cell

    Set shpTable = ActiveWindow.Selection.ShapeRange.Table

    With shpTable.Cell(1, 1).Shape.TextFrame
    .TextRange.Font.Size = 14
    .TextRange.Font.Name = "Arial"
    .TextRange.Font.Color.RGB = 16777215
    .TextRange.Font.Bold = msoTrue
    .HorizontalAnchor = msoAnchorCenter
    .VerticalAnchor = 3
    .Parent.PickUp
    End With

    For Each objTableRow In shpTable.Rows
    For Each cl In objTableRow.Cells
    cl.Shape.Apply
    Next cl
    Next objTableRow

    End Sub[/VBA]There is a way around the flickering, which speeds thing up slightly (but not a great deal)
    I did try an alternative, working with the shapes in the Group that makes up the table, rather than table cells, which is much faster but for some reason I haven't quite worked out - it fails randomly when indexing the groupitem. I'll see if I can get it working sometime...
    K :-)

Posting Permissions

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