Reputation: 1
I'm trying paste a chart in PowerPoint using the command:
PPApp.CommandBars.ExecuteMso "PasteExcelChartSourceFormatting"
It's working very well, but when I try to change size and position the code don't make effect in chart properties and don't return errors. When I use the command:
Shapes.Paste.Select
I can change and resize the chart, but don't work for me because I want "PasteExcelChartSourceFormatting". What are my mistakes?
My full code With PPSlide
ActiveChart.ChartArea.Copy
PPApp.CommandBars.ExecuteMso "PasteExcelChartSourceFormatting"
'.Shapes.Paste.Select
With PPApp.ActiveWindow.Selection.ShapeRange
.LockAspectRatio = msoFalse
.Width = 680.314961
.Height = 453.543307
.Left = 19.8425197
.Top = 56.6929134
End With
Upvotes: 0
Views: 5203
Reputation: 1125
Seems to be a common problem when calling ExecuteMso in PowerPoint. Try inserting:
Application.DoEvents()
right after the ExecuteMso() command. That works in most (but not all, in my experience) situations.
If MSFT would simply expose these paste methods and other thing (like Undo) in the object model, that would avoid the need to call ExecuteMso and make like easier for developers.
Upvotes: 0
Reputation: 14809
Try something along these lines:
Dim oSh As Object ' or PowerPoint.Shape if you've set a reference to PPT
Dim lSlideIndex As Long
lSlideIndex = 1
CommandBars.ExecuteMso "PasteExcelChartSourceFormatting"
Set oSh = ActivePresentation.Slides(lSlideIndex).Shapes(ActivePresentation.Slides(lSlideIndex).Shapes.Count)
With oSh
.Left = 0
.Width = 100
End With
Upvotes: 1
Reputation: 1
I tried to do this, but doesn't work. Seems that the presentation doesn't update the shapes numbers. I tried to this:
lSlideIndex = oPPtApp.ActiveWindow.View.Slide.SlideIndex
MsgBox oPPtApp.ActivePresentation.Slides(lSlideIndex).Shapes.Count
oPPtApp.CommandBars.ExecuteMso "PasteExcelChartSourceFormatting"
MsgBox oPPtApp.ActivePresentation.Slides(lSlideIndex).Shapes.Count
The command is executed and the shape entered, but the msgbox returns the same value before and after the command. "oPPtApp.CommandBars.ExecuteMso" But when I run in different routines, the numbers have been updated. As if I run a routine to the command "oPPtApp.CommandBars.ExecuteMso" and one for resizing shapes works perfectly
Upvotes: 0