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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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