PDA

View Full Version : Using automatic selection of paste special option for other commands



RandomGerman
11-02-2015, 05:04 AM
A few month ago, John taught me to use


CommandBars.ExecuteMso ("PasteSourceFormatting")

(in 2010 and onwards) for pasting in ready-to-use-objects from a hidden presentation. I still love that solution and working with the pasted objects I especially appreciate that they already are selected after being pasted in. But today I tried to specialize the selection and select the text of a the selected object, which would make me able to overwrite it asap.


Sub CopyfromHiddenPresentation()
Dim src As Presentation
Dim trg As Slide
Dim target As Presentation
Dim shp As Shape
'Open the source presentation
Set target = Application.Presentations.Open("C:\Users\...\Desktop\CopyTest.pptx")
Set src = Presentations("CopyTest.pptx")

'Go to the wanted slide
ActiveWindow.View.GotoSlide (2)

'Select all shapes on the slide
src.Slides(2).Shapes.SelectAll

'Copy the whole selection
ActiveWindow.Selection.ShapeRange.Copy

'Close the source presentation
With Application.Presentations("CopyTest.pptx")
.Close
End With

'Go to target slide and paste, keeping format
Set trg = ActiveWindow.View.Slide
CommandBars.ExecuteMso ("PasteSourceFormatting")

ActiveWindow.Selection.TextRange.Select

End Sub



The shape in my example on slide 2 of the hidden presentation is just one grey rectangle with a few words text in it.

It seems, the macro doesn't realize, something is already selected. I always get an error saying "nothing appropriate is selected". But in fact, the shape is selected. When I debug, the last line of the code gets marked:


ActiveWindow.Selection.TextRange.Select

When I click continue then, I get the result I want! So all I need to know is, how to get rid of the break with the error message ... How can I make the macro understand, something is already selected? I also already tried fitting in some piece of code, first finding out, how many objects are selected, but the same thing occured: The macro said, no object to be selected.

Thank you,
RG


I know, codes always do, what I tell them to do. Not what I want them to do ...