none
Deleting objects from a Microsft Word document RRS feed

  • Question

  • I have a MS word document (template). My program asks the user questions and based on those questoins it fills out the template for them programmatically.

    Some of the questions on the template requires the user to circle an answer. Instead of making the user do double work, I circled all possible answers. Since I know what the user answered in my program, I would like to know if there is a way to go throug the template and delete certain drawing objects (the circles around the text).

    Can I give each object an ID number in word and tell my program delete objects out of the document that match that ID number?

    Thanks in advance for your assistance.


    -Nothing to see. Move along.

    • Moved by Fred Bao Monday, May 12, 2014 2:49 AM Office Related
    Friday, May 9, 2014 4:14 PM

Answers

  • Hi,

    >>, I would like to know if there is a way to go throug the template and delete certain drawing objects (the circles around the text).<<

    What do you mean by certain drawing objects? Would you mind share the code snippet that how you created the circles?

    Does it means a shape? If I understand correctly, we couldn’t set the id for a shape but we can set its name. And we can delete the shape by its name like code below:

    Sub DeleteShapes()
    
    Dim aShape As Shape
    
    For Each aShape In Application.ActiveDocument.Shapes
    
              If aShape.Name = "Flowchart: Connector 3" Then
    
                 aShape.Delete
    
              End If
    
    Next aShape
    
    End Sub
    

    Screen shot:

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 7:06 AM
    Moderator
  • Hi Blacksaibot

    You can assign Shape objects in Word a NAME property and use that as an index value.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, May 13, 2014 10:12 AM
    Moderator

All replies

  • Ask here: http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev


    Visual C++ MVP

    Friday, May 9, 2014 8:39 PM
  • Hi,

    >>, I would like to know if there is a way to go throug the template and delete certain drawing objects (the circles around the text).<<

    What do you mean by certain drawing objects? Would you mind share the code snippet that how you created the circles?

    Does it means a shape? If I understand correctly, we couldn’t set the id for a shape but we can set its name. And we can delete the shape by its name like code below:

    Sub DeleteShapes()
    
    Dim aShape As Shape
    
    For Each aShape In Application.ActiveDocument.Shapes
    
              If aShape.Name = "Flowchart: Connector 3" Then
    
                 aShape.Delete
    
              End If
    
    Next aShape
    
    End Sub
    

    Screen shot:

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 7:06 AM
    Moderator
  • Hi Blacksaibot

    You can assign Shape objects in Word a NAME property and use that as an index value.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, May 13, 2014 10:12 AM
    Moderator