ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close na "on the fly" created Listbox if ignored by the user? (https://www.excelbanter.com/excel-programming/448205-close-na-fly-created-listbox-if-ignored-user.html)

Snowfire

Close na "on the fly" created Listbox if ignored by the user?
 
How could I use vba to close an "on the fly" created Listbox if
ignored by the user.... if I use the Worksheet_SelectionChange event
and say.. ActiveSheet.ListBoxes("OfficeList").Delete for example it
is fine if the listbox is open but gives and error if not. I have
tried to poll for any open Listboxes ( and hences close them ) but
can't get the code right or am I on the "wrong road" ...?
Cheers

witek

Close na "on the fly" created Listbox if ignored by the user?
 
Snowfire wrote:
How could I use vba to close an "on the fly" created Listbox if
ignored by the user.... if I use the Worksheet_SelectionChange event
and say.. ActiveSheet.ListBoxes("OfficeList").Delete for example it
is fine if the listbox is open but gives and error if not. I have
tried to poll for any open Listboxes ( and hences close them ) but
can't get the code right or am I on the "wrong road" ...?
Cheers



ActiveSheet.ListBoxes("OfficeList") generates error if OfficeList does
not exist. so use that fact

function GetOfficeListBox as listbox
on error goto trapit
set GetOfficeListbox = ActiveSheet("officelist")
exit function
trapit:
set GetOfficeListbox = nothing
end function


in your main program


dim olb as listbox
set olb = getOfficeListbox ()
if not olb is nothing then
olb.delete
end if

--------

eventually getOfficeListbox can have a name of listbox as paramater and
be used to get listbox reference or nothing for any listbox.




All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com