Friday, March 14, 2014

How to Remove Shape in Ms Word

Leave a Comment
How to remove shape in Ms Word using VBA Macro
In Microsoft word, it provides the approach to write VBA Function known as Macro to perform automatically tasks in Ms Word. We can also implement VBA class objects with VBA’s function for the automatically tasks. First, write your own function to remove all shapes which contain in Word File. VBA contains a Class Object called Shape and Shapes to deal with all shapes. We can use Shape Object to delete, select or duplicate the shape.

Code Sample to delete all shapes
Here is complete code example to remove all shapes. This example uses Shapeobject in VBA:


SubRemoveShapes()
    Dim oShape AsShape
    Do
        For EachoShape In ActiveDocument.Shapes
           ' Delete the shape
            oShape.Delete
        NextoShape
    Loop UntilActiveDocument.Shapes.Count = 0
   
    Set oShape = Nothing
End Sub

How to test this Code
1. Open Ms Word
2. Open VB Editor or Alt+F11
3. Create new module
4. Copy and paste the Code
5. Go back to you word and go to Macro Dialog then select the Macro Name RemoveShape and Click on Run


That’s all on how to remove all shapes in Ms Word. 

0 comments :

Post a Comment

DMCA.com Protection Status