Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default ActiveControl problem

I am attempting to service several Excel controls from the same macro code as
shown below:

Sub WHOAMI()
Dim ctrl As Control
Dim getactivectlname, mytext
ctrl = screen.ActiveControl
mytext = ctrl.Name
MsgBox ("The Value Is " & ctrl & " text= " & mytext & " thats all")
End Sub

WHOAMI launches, but on the "CTRL = SCREEN.ACTIVECONTROL" statement I get a
"Runtime Error 424 -- Object Required" error.

This is on Excel XP (2002). Any Ideas? Currently I have no DECLARATIONS.

Thanks for the help. Dave

--
Dave Ackmann
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 449
Default ActiveControl problem

Hi Dave

See if this is of use:

Sub WHOAMI()
MsgBox Application.Caller
End Sub

HTH. Best wishes Harald

"DAACKM" wrote in message
...
I am attempting to service several Excel controls from the same macro code
as
shown below:

Sub WHOAMI()
Dim ctrl As Control
Dim getactivectlname, mytext
ctrl = screen.ActiveControl
mytext = ctrl.Name
MsgBox ("The Value Is " & ctrl & " text= " & mytext & " thats all")
End Sub

WHOAMI launches, but on the "CTRL = SCREEN.ACTIVECONTROL" statement I get
a
"Runtime Error 424 -- Object Required" error.

This is on Excel XP (2002). Any Ideas? Currently I have no DECLARATIONS.

Thanks for the help. Dave

--
Dave Ackmann


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default ActiveControl problem

Thanks, Harald. This was just what I needed.
--
Dave Ackmann


"Harald Staff" wrote:

Hi Dave

See if this is of use:

Sub WHOAMI()
MsgBox Application.Caller
End Sub

HTH. Best wishes Harald

"DAACKM" wrote in message
...
I am attempting to service several Excel controls from the same macro code
as
shown below:

Sub WHOAMI()
Dim ctrl As Control
Dim getactivectlname, mytext
ctrl = screen.ActiveControl
mytext = ctrl.Name
MsgBox ("The Value Is " & ctrl & " text= " & mytext & " thats all")
End Sub

WHOAMI launches, but on the "CTRL = SCREEN.ACTIVECONTROL" statement I get
a
"Runtime Error 424 -- Object Required" error.

This is on Excel XP (2002). Any Ideas? Currently I have no DECLARATIONS.

Thanks for the help. Dave

--
Dave Ackmann



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default ActiveControl problem

Can you explain where the controls are located (on a worksheet or on a
userform)?

If they are on a worksheet, did you get them from the Forms toolbar or from the
Control toolbox toolbar or even from the drawing toolbar?

If they are on a worksheet and you got them from the Forms toolbar (or the
drawing toolbar), you may want to look at application.caller.

If they are on a worksheet and you got them from the Control toolbox toolbar,
you may want to look at John Walkenbach's site:

http://spreadsheetpage.com/index.php..._subrouti ne/

If the controls are on a userform, then I'm not sure how you run WhoAmi, but
this may give you an idea.

Option Explicit
Private Sub CommandButton1_Click()

Dim ctrl As Control
Dim myText As String

Set ctrl = Me.ActiveControl

myText = ctrl.Name
MsgBox "The Value Is " & ctrl.Value & vbLf _
& "text= " & myText & vbLf _
& " thats all"

End Sub
Private Sub UserForm_Initialize()
'so it doesn't become the active control
Me.CommandButton1.TakeFocusOnClick = False
End Sub

DAACKM wrote:

I am attempting to service several Excel controls from the same macro code as
shown below:

Sub WHOAMI()
Dim ctrl As Control
Dim getactivectlname, mytext
ctrl = screen.ActiveControl
mytext = ctrl.Name
MsgBox ("The Value Is " & ctrl & " text= " & mytext & " thats all")
End Sub

WHOAMI launches, but on the "CTRL = SCREEN.ACTIVECONTROL" statement I get a
"Runtime Error 424 -- Object Required" error.

This is on Excel XP (2002). Any Ideas? Currently I have no DECLARATIONS.

Thanks for the help. Dave

--
Dave Ackmann


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"