Copy the form in Word 2010 without. Choose?

Can I copy a shape in Word 2010 without using it .Select

? According to Dev Center the property Anchor

returns the anchor range of the shape. Could this be the way forward? However, the code below returns an error.

Sub createShape()
    Set myShape = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 1, 1, 1, 1)
    myShape.Anchor.Copy
End Sub

      

+3


source to share


2 answers


While it is not possible to copy a shape without selecting it, you can duplicate a shape without selecting it (which was the reason for copying it in the first place). The following code gives me what I was looking for:



Sub createShape()
    Set myshape = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 100, 100, 100, 100)
    Set anothershape = myshape.Duplicate
End Sub

      

+1


source


If you have what you're looking for, that's great, but you can copy the shape as such by copying the paragraph (or range) that the shape is anchored to. For example:

Sub createShape()
   Dim myShape As Shape, myRange As Range

   Set myShape = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 10, 10, 10, 10)
   Set myRange = myShape.Anchor.Paragraphs(1).Range
   myRange.Copy
End Sub

      



The problem, however, is that it will copy whatever text in the paragraph you anchor it to, or your anchor, maybe in a table, which might cause strange things.

You can also change the shape to an inline shape after inserting it to fit the text and have a more obvious range, since anchor points tend to move and be generally unpredictable.

+1


source







All Articles