sksanjeev786
Well-known Member
- Joined
- Aug 5, 2020
- Messages
- 961
- Office Version
- 365
- 2016
- Platform
- Windows
Hi Team,
The below macro is working fine for me the requirement is to copy the table (content Placeholder 8) from Slide 2 to Slide 1 but with the below macro
Slide 2 Table is copying on Slide 2(Duplicate existing slide 2 table) only instead Slide 1 (and on Slide 1 some image is popping up after generating the macro)
The below macro is working fine for me the requirement is to copy the table (content Placeholder 8) from Slide 2 to Slide 1 but with the below macro
Slide 2 Table is copying on Slide 2(Duplicate existing slide 2 table) only instead Slide 1 (and on Slide 1 some image is popping up after generating the macro)
VBA Code:
Sub CopyTableWithinPPT()
Dim sourceSlide As Slide
Dim destSlide As Slide
Dim sourceTable As Table
Dim destTable As Table
Dim shp As Shape
Dim newShape As Shape
Set sourceSlide = ActivePresentation.Slides(2)
Set destSlide = ActivePresentation.Slides(1)
For Each shp In sourceSlide.Shapes
If shp.Type = msoPlaceholder And shp.Name = "Content Placeholder 8" Then
If shp.HasTable Then
Set sourceTable = shp.Table
Exit For
End If
End If
Next shp
If Not sourceTable Is Nothing Then
Set newShape = sourceTable.Parent.Duplicate()(1)
newShape.Top = 100
newShape.Left = 100
newShape.Width = sourceTable.Parent.Width
newShape.Height = sourceTable.Parent.Height
newShape.LockAspectRatio = msoTrue
destSlide.Shapes.AddShape newShape.Type, newShape.Left, newShape.Top, newShape.Width, newShape.Height
For Each shp In destSlide.Shapes
If shp.Type = msoTable Then
Set destTable = shp.Table
Exit For
End If
Next shp
If Not destTable Is Nothing Then
Dim i As Long
For i = 1 To sourceTable.Rows.Count
CopyRow sourceTable.Rows(i), destTable.Rows(i)
Next i
MsgBox "Table copied successfully from slide 2 to slide 1.", vbInformation
Else
MsgBox "Error: Destination table not found.", vbExclamation
End If
Else
MsgBox "Error: Source table not found on slide 2's Content Placeholder 8.", vbExclamation
End If
End Sub
Sub CopyRow(ByVal sourceRow As Row, ByVal destRow As Row)
Dim i As Long
For i = 1 To sourceRow.Cells.Count
With sourceRow.Cells(i)
destRow.Cells(i).Shape.TextFrame.TextRange.Text = .Shape.TextFrame.TextRange.Text
destRow.Cells(i).Shape.TextFrame.TextRange.Font.Color.RGB = .Shape.TextFrame.TextRange.Font.Color.RGB
End With
Next i
End Sub