tags:

views:

1280

answers:

3

I have a Word document that contains a command button named "update".

How can I delete this button using VBA?

thanks, Paul

+1  A: 

This should do it :

For Each o In ActiveDocument.InlineShapes      

   If o.OLEFormat.Object.Name = "update" Then
        o.Delete
    End If

Next
Peter
A: 

I have tried this code. It runs without error, but the button does not get deleted. I have stepped through the code and the o.Delete command is executed. Just doesn't seem to do anything. Can you suggest what the problem could be?

Thanks, Chris

Chris - the value of Object.Name appears to be case sensitive.Maybe that's your problem?Paul
tequila2k
A: 

Hey Chris,

I think when you said 'Button Name' you ment 'Button Caption'; please try below code -

For Each o In ActiveDocument.InlineShapes
   If o.OLEFormat.Object.Caption = "update" Then
        o.Delete
    End If
Next

Regards, Nilesh

PS: the caption is case sensitive, so you may want to check the case for caption.

Nilesh Deshmukh