Consulting

Results 1 to 4 of 4

Thread: Solved: copy & paste macro gives inconsistent results

  1. #1
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    3
    Location

    Angry Solved: copy & paste macro gives inconsistent results

    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. [vba]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[/VBA] 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?
    Last edited by tegan; 09-18-2011 at 01:37 AM.

  2. #2
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    3
    Location
    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?

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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:

    [vba]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[/vba]
    Last edited by John Wilson; 09-25-2011 at 03:03 PM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Newbie
    Joined
    Sep 2011
    Posts
    3
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •