Link to home
Start Free TrialLog in
Avatar of Ashkan Lotfipour
Ashkan Lotfipour

asked on

How to reposition a table in powerpoint from excel?

Hello there
I have a VBA code that copies data from excel to a power point presentation. the problem that I have is that I cannot set the position of the copied table in powerpoint. it doesn't work in a for loop.

Sub ExcelRangeToPowerPoint()
    
        Application.ScreenUpdating = False
        Dim rng As Range
        Dim PowerPointApp As Object
        Dim myPresentation As Object
        Dim mySlide As Object
        Dim myShape As Object
        Dim PPPres As Object
        Dim PPT As PowerPoint.Application
        Dim SlideNum As Integer
        Dim counter As Integer

    Set PPT = New PowerPoint.Application
    PPT.Visible = True
    PPT.Presentations.Open Filename:="C:\Users\Ashkan\Desktop\Powerpoint autoupdate\1.pptm"
    
For counter = 1 To 3
    SlideNum = counter
    Sheets("Sheet" & SlideNum).Select
    'Copy Range from Excel
    Set rng = ThisWorkbook.ActiveSheet.Range("A1:B5")
    rng.Copy
      
    'Paste to PowerPoint and position
      Set myPresentation = PPT.ActivePresentation
      myPresentation.Slides(SlideNum).Shapes.Paste
      
      Set mySlide = myPresentation.Slides(SlideNum)
      Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
        Set position:
          myShape.Left = 128.88
          myShape.Top = 68.4
          
          Set mySlide = Nothing
          
Next counter

    Application.CutCopyMode = False
    Application.ScreenUpdating = True
  
End Sub

Open in new window


Line 29 to 33 is not working for table number 2 and 3. it only repositions the table 1.
how can I select this table in power point in order to reposition it?
Avatar of Rgonzo1971
Rgonzo1971

HI,

Could you send dummies? Code seems right

Regards
Avatar of Ashkan Lotfipour

ASKER

Sure.
1.pptx
1.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great!!
Thank you for your assistance.