deleting OLE control from inactive worksheet

S.Br.

Board Regular
Joined
Oct 5, 2012
Messages
94
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007
Dear Mr.Excel, Happy Holidays;
In my Add-In I monitor the SheetActivate event, and create an OLE control by calling active sheet's .OLEObjects.Add() method.
When the sheet de-activates its SheetDeactivate event is fired and I need to delete the control by calling its .Delete() member.
Excel is very unhappy with this approach because it is not designed to work with inactive worksheets: the SheetDeactivate event
is called when the worksheet is inactive. How do I get around this design? How do I delete an OLEObject from inactive worksheet?
Many thanks in advance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Don't use ActiveSheet, use the name or codename of the sheet that conatains the oleobject control ... Something like this :
Code:
Private Sub Worksheet_Deactivate()
 [COLOR=#ff0000][B]Sheet1[/B][/COLOR].OLEObjects("[COLOR=#ff0000][B]CommandButton1[/B][/COLOR]").Delete
End Sub

Change the names in red to suit.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top