ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to reach Application Objects in Events? (https://www.excelbanter.com/excel-programming/383893-how-reach-application-objects-events.html)

NOPIK

How to reach Application Objects in Events?
 
Need to perform Range("A:A").Find operation in
ActiveSheet.Button1.OnClick event handler in module (not in a class!).
Button - member of the sheet. But, Application members seems to be
not visible for events until they specially declared (if I call event
handler as procedure it works).
Is there any common way to get any objects, visible in ordinal modules?


Tom Ogilvy

How to reach Application Objects in Events?
 
Buttons from the forms toolbar (not the control toolbox toolbar) can have a
macro assigned to them from a general module. This is essentially a click
event, because it is fired when the control is clicked.

assume we assign the macro btn_click (any name can be chosen) to the button

Sub btn_click()
dim sName as string
dim btn as Button
sName = Application.Caller
set btn = activesheet.buttons(sName)
msgbox btn.Caption & ", " & btn.Name
End Sub

if not prompted, you can right click on the button and choose assign macro
from the popup menu.

--
Regards,
Tom Ogilvy




You can name the procedure anything, but once you rubberband the button
control on the spreadsheet, you will be prompted to assign a macro and it
will display a dialog similar to Tools=Macro=macros showing the
subroutines in general modules.
"NOPIK" wrote in message
ps.com...
Need to perform Range("A:A").Find operation in
ActiveSheet.Button1.OnClick event handler in module (not in a class!).
Button - member of the sheet. But, Application members seems to be
not visible for events until they specially declared (if I call event
handler as procedure it works).
Is there any common way to get any objects, visible in ordinal modules?




NOPIK

How to reach Application Objects in Events?
 
Well... I know how to operate VB objects in common :-) More concrete:
I need to access objects outside of event visible range (but inside
the Application visible range).
Example: Application.MyOwnProperty visible for any module or class,
except events.
Can I access this property or method (may be, from other root of
Application object)?


Tom Ogilvy

How to reach Application Objects in Events?
 
I don't know how you would make it visible to everything but events or why
you would want to.

But if you instantiate application.level events, you could use that class
module to hold your application level property.

http://www.cpearson.com/excel/appevent.htm

Even if you did this, however, it wouldn't be independent of a workbook -
you would still have to open and execute the code in a workbook to create
the property.

--
Regards,
Tom Ogilvy



"NOPIK" wrote in message
ps.com...
Well... I know how to operate VB objects in common :-) More concrete:
I need to access objects outside of event visible range (but inside
the Application visible range).
Example: Application.MyOwnProperty visible for any module or class,
except events.
Can I access this property or method (may be, from other root of
Application object)?





All times are GMT +1. The time now is 02:46 PM.

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