Share via

text alignment in a powerpoint table

Anonymous
2010-12-02T16:04:05+00:00

Hi All,

I am writing a macro that copies and pastes data from excel into a powerpoint table and as the program loops and copies each cell over, I want it to align the text on the right hand side of the powerpoint cell.  The code I have written is:

Selection.Copy    <----copies excel data

                    PowerPoint.Application.Activate

                    With PowerPoint.Application

                            PowerPoint.ActivePresentation.Slides(4).Select

                            oAggprodtable.Cell(2 + x, j + 1).Select

                            oAggprodtable.Application.ActiveWindow.View.PasteSpecial (ppPasteText)

                           oAggprodtable.Application.ActiveWindow.Selection.TextRange.ParagraphFormat.Alignment = ppAlignRight

it is this last line of code that I am having trouble with as when I try to run the program, I get a run time error that says "Nothing appropriate is currently selected."  Im just not sure how to handle this problem in powerpoint.  Any and all help would be much appreciated

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Steve Rindsberg 99,161 Reputation points MVP Volunteer Moderator
2010-12-03T23:43:21+00:00

Since you already have a reference to the table, change your code to this:

Selection.Copy

                    PowerPoint.Application.Activate

                    With PowerPoint.Application

                    'With ActivePresentation.Slides(4)

                    With oAggProdtable.Cell(2 + x, j + 1).Shape.TextFrame.TextRange

                            .PasteSpecial (ppPasteText)

                            .ParagraphFormat.Alignment = ppAlignRight

                    End With

                    'End With

                    End With


Steve Rindsberg PowerPoint MVP

PowerPoint FAQ

PPTools Add-ins for PowerPoint

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-12-06T17:17:05+00:00

    that did it!  Thanks for the help everyone!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-12-03T21:50:51+00:00

    Declare oAggprodtable as table and not a varient object, and if you have selected the table before running the code you can refrence it with the following code

    DimoAggprodtable As Table

    Set oAggprodtable = ActiveWindow.Selection.ShapeRange(1).Table


    Best regards, Harvey

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-12-03T18:07:58+00:00

    Hmm Okay thanks for the reply.  I have defined oAggprodtable as a table at the beginning of my code and have also set oAggprodtable as a specific table using this code:   

    Set oAggprodtable = ActiveWindow.Selection.SlideRange.Shapes("Group 4383").Table

    the code you posted above seems to be giving me some problems still.  It is giving me the following error: "The item with the specified name wasn't found."  Clearly this has something to do with how I set the table or how I am referencing it here but I cant figure it out.  The code I have written using your suggestion is:

     Selection.Copy

                        PowerPoint.Application.Activate

                        With PowerPoint.Application

                        With ActivePresentation.Slides(4)

                        With .Shapes("oAggprodtable").Table.Cell(2 + x, j + 1).Shape.TextFrame.TextRange

                                .PasteSpecial (ppPasteText)

                                .ParagraphFormat.Alignment = ppAlignRight

                        End With

                        End With

                        End With

    I just dont know what is wrong with it now..Thanks!

    Was this answer helpful?

    0 comments No comments
  4. Steve Rindsberg 99,161 Reputation points MVP Volunteer Moderator
    2010-12-02T20:07:35+00:00

    Life's a lot simpler if you avoid selecting anything.

    With PowerPoint.Application

    With ActivePresentation.Slides(4)

    ' what's oAggprodtable?  Have you defined this elsewhere?  It doesn't make sense as is, but ..

    with .Shapes("name of table").Table.Cell(2+x, j+1).Shape.TextFrame.TextRange

    .Paste

    .ParagraphFormat.Alignment = ppAlignRight

    end with

    End With


    Steve Rindsberg PowerPoint MVP

    PowerPoint FAQ

    PPTools Add-ins for PowerPoint

    Was this answer helpful?

    0 comments No comments