View Single Post
 
Old 04-13-2012, 12:51 AM
TishyMouse TishyMouse is offline Windows XP Office 2007
Novice
 
Join Date: Feb 2012
Posts: 22
TishyMouse is on a distinguished road
Default

Thanks for the response Paul. Actually the problem was not the selection, the problem was that the code never even entered the For...Each loop - it didn't pick up the fact that there were shapes in the document at all. It transpires that this is due to the shapes being in a different StoryRange in the document. I finally managed to select the shapes (Text Frames in this case) using the code below. I was able to successfully copy and paste the content of each of the text frames into a separate document. Ideally I would have just liked to remove the text frames in-situ (copying the content into the main body of the document) but I couldn't get this to work.


Code:
Sub SelectShapes()

    Set docSource = ActiveDocument
    Set docTarget = Documents.Add("Normal")

    docSource.Activate

    For Each sr In docSource.StoryRanges
      If sr.StoryType = wdTextFrameStory Then
        sr.Select

         done = False
         While Not done
            sr.Select
         
            Selection.WholeStory
            Selection.Copy
            docTarget.Activate
            Selection.PasteAndFormat (wdPasteDefault)
            docSource.Activate
                        
            Set sr = sr.NextStoryRange
            If sr Is Nothing Then done = True
         Wend
      End If
   Next sr

End Sub
Reply With Quote