PDA

View Full Version : Solved: copy & paste macro gives inconsistent results



tegan
09-18-2011, 01:24 AM
small problem, I'm getting inconsistent results with a simple copy/paste script in PP 2007 I'm trying to pull lines of text from shapes on other slides and merge them into a single shape that already exists on another slide. application.activepresentation.slide(1).shape(2).textrange.paragraph.line(1 ).copy

application.activepresentation.slide(2).shape(3).textrange.paragraph.line(1 ).paste

application.activepresentation.slide(1).shape(4).textrange.paragraph.line(1 ).copy

application.activepresentation.slide(2).shape(3).textrange.paragraph.line(2 ).paste sometimes the macro works and the new paragraph is what i want. sometimes only one pastes, and sometimes only the other pastes. it may be a clipboard issue, because the results change when I select shapes outside of the macro session and cntrl-C them. I found "application.cutcopymode=False" to clean the clipboard but got an error trying to include it in the script. Do i need to name these shapes so Z-order doesn't get outa whack?

tegan
09-18-2011, 09:46 PM
weird. I was even more specific on what i wanted to copy using .characters and it worked fine for a number of same type powerpoints. after saving, closing, and reopening, the macro wouldn't work at all.

Is there a way to set one of the lines equal to another and skip using the copy/paste?

John Wilson
09-25-2011, 02:52 PM
There are so many errors in the code there's no way it ever worked!

SlideS(1) etc
ShapeS(1) etc
ParagraphS(1) etc
LineS(1) etc
Shapes cannot have a textrange, textframes have textranges.
Sorry that sounds more critical than was meant.

Do you need to paste the text formatted exactly as the original or will just the text itself be OK?

This might work if so:

Sub settext()
Dim strtext As String
With ActivePresentation
strtext = .Slides(1).Shapes(2).TextFrame.TextRange.Paragraphs(1).Lines(1) _
& .Slides(1).Shapes(4).TextFrame.TextRange.Paragraphs(1).Lines(1)
.Slides(2).Shapes(3).TextFrame.TextRange = strtext
End With
End Sub

tegan
09-25-2011, 10:10 PM
You're right of course about the code above never working, I forgot to mention that it was air code from my head, a horrible slip-up since others do happen upon it. I was able to get around the original problem by inserting a .slides(1).shapes(1).copy to flush (I guess) the clipboard before each line of text copy & paste.

Your solution is elegant as always. Thanks for being critical and for the response. I'm still in the brute forces stages of vba.

and now I'm looking for a way to mark this thread solved.