Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete 1 of Multiple Command Buttons (Word)

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
I have a Word document with multiple command buttons. One command button (cmdIntroduction) in particular initiates a user form. When the user selects Submit on the user form, the folling code runs:

Code:
For Each obj In ActiveDocument.InlineShapes
    If obj.OLEFormat.Object.Name = "cmdIntroduction" Then
    obj.Delete
   End If
Next

...hence deleting the cmdIntroduction command button as intended. However, once this is accomplished, none of my other command buttons on the document now work. What am I missing?

Thanks!
 

hi,

Personally I would not delete the object. Rather make it disabled or even invisible.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sounds like an adequate solution. However, I am not realizing what the code should be in order to accomplish this. Tried updating to obj.Visible = False, but did not do the trick. :\
 
but did not do the trick
Exactly what does that mean, from the spectrum of possible interpretations.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
It did not make it invisible.

Run-time error 438: Object doesn't support this property or method.
 
would this work???
Code:
dim i as integer
For for i = ActiveDocument.InlineShapes.Count to 1 step -1
   with ActiveDocument.InlineShapes(i)
     If .OLEFormat.Object.Name = "cmdIntroduction" Then
       .Delete
       exit for
     End If
   end with
Next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Produces the same result as my original issue. Once this code is run, the intended object deletes, however all other command buttons on the document seem to change to a disabled state - click on them, nothing happens.
 
What happens if you change each inlineshape object to a shape object?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
well, of course you need to CHANGE the type of object in your code to a Shape and the Shapes collection.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The original code I have posted, was found on the internet. I honestly don't know what the difference between an inline shape and a shape is and am unable to find it defined. Therefore, I don't know that what I have posted is even the correct start for what I need to do. Had I not posted the code I have found, would you have suggested something similar, or perhaps, is there a simpler way to approach?
 
What are you trying to achieve? Please don't give me how you think it ought to be done. Tell me FUNCTIONALLY what you need to do.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The following works fine for me:
Code:
Sub Test()
Dim IShp As InlineShape
For Each IShp In ActiveDocument.InlineShapes
     If IShp.OLEFormat.Object.Name = "cmdIntroduction" Then
       IShp.Delete
       Exit For
     End If
Next
End Sub
After calling the above from the ActiveX control concerned (or from a different one), other ActiveX controls in the document continue to work.

Cheers
Paul Edstein
[MS MVP - Word]
 
After a little more trouble-shooting, I have found that the issue seems to have to do with the document being a template (dotm). When testing the buttons from within the template, they work properly. However, when an iteration of that template is created (Document1.doc), the command button deletes, yet the other controls cease to work.
 
In that case, there's probably an error in your coding for the other controls (eg they refer to 'ThisDocument' instead of 'ActiveDocument').

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top