Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Application.Caller syntax for worksheets?


It's got to be an obvious mistake, but I'm having trouble with the
following code:


Code:
--------------------
Private Sub cmdInventory_Click()

Dim selOpt As OptionButton
Dim studyName As String

Set selOpt = ActiveSheet.OptionButtons(Application.Caller)

If selOpt.Value = True Then
studyName = selOpt.Name
MsgBox studyName
End If

End Sub
--------------------


Execution from the worksheet yields a:

"Run-time error '1004':

Unable to get the OptionButtons property of the Worksheet class"


Execution from the VBA editor yields a:

"Run-time error '1004':
Application-defined or object-defined error"


What syntax have I goofed??

The examples I have use the above syntax, but I can't seem to get them
to go either...


--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Application.Caller syntax for worksheets?

Hi Hi Ouka,

Try changing:

If selOpt.Value = True Then



to

If selOpt.Value = xlOn Then

---
Regards,
Norman


"Ouka" wrote in message
...

It's got to be an obvious mistake, but I'm having trouble with the
following code:


Code:
--------------------
Private Sub cmdInventory_Click()

Dim selOpt As OptionButton
Dim studyName As String

Set selOpt = ActiveSheet.OptionButtons(Application.Caller)

If selOpt.Value = True Then
studyName = selOpt.Name
MsgBox studyName
End If

End Sub
--------------------


Execution from the worksheet yields a:

"Run-time error '1004':

Unable to get the OptionButtons property of the Worksheet class"


Execution from the VBA editor yields a:

"Run-time error '1004':
Application-defined or object-defined error"


What syntax have I goofed??

The examples I have use the above syntax, but I can't seem to get them
to go either...


--
Ouka
------------------------------------------------------------------------
Ouka's Profile:
http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Application.Caller syntax for worksheets?

From your variable names, it looks like cmdInventory is a commandbutton (from
the control toolbox???).

If that's the case, application.caller won't work.

if cmdInventory is a sub in a general module that's assigned to a bunch of
optionbuttons (from the Forms toolbar), then never mind.

Ouka wrote:

It's got to be an obvious mistake, but I'm having trouble with the
following code:

Code:
--------------------
Private Sub cmdInventory_Click()

Dim selOpt As OptionButton
Dim studyName As String

Set selOpt = ActiveSheet.OptionButtons(Application.Caller)

If selOpt.Value = True Then
studyName = selOpt.Name
MsgBox studyName
End If

End Sub
--------------------

Execution from the worksheet yields a:

"Run-time error '1004':

Unable to get the OptionButtons property of the Worksheet class"


Execution from the VBA editor yields a:

"Run-time error '1004':
Application-defined or object-defined error"


What syntax have I goofed??

The examples I have use the above syntax, but I can't seem to get them
to go either...

--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Application.Caller syntax for worksheets?


Norman - Changing "true" to "xlOn" did not work, getting the same error.


Dave - the option buttons and the command buttons are all on a
worksheet, not a user form.

The command button is built at design time, but the option buttons are
built by the user at run time, hence I cannot know what they are going
to be named ahead of time for any "if optionbutton1.value = true then"
code.

I need VBA to return to me the name of selected option button so I can
assign that name as a variable to use in a calling procedure in my
code.


--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Application.Caller syntax for worksheets?

You could have used optionbuttons from the Forms Toolbar or optionbuttons from
the Control toolbox toolbar on your worksheet.

It sounds like you used the optionbuttons from the Forms toolbar.

dim myOptBtn as optionbutton
for each myOptBtn in activesheet.optionbuttons
if myoptbtn.value = xlon then
msgbox myoptbtn.caption
exit for
end if
next myoptbtn

Just in case they were from the Control toolbox toolbar:

Dim OLEObj As OLEObject
For Each OLEObj In ActiveSheet.OLEObjects
If TypeOf OLEObj.Object Is MSForms.OptionButton Then
If OLEObj.Object.Value = True Then
MsgBox OLEObj.Object.Caption
Exit For
End If
End If
Next OLEObj


Ouka wrote:

Norman - Changing "true" to "xlOn" did not work, getting the same error.

Dave - the option buttons and the command buttons are all on a
worksheet, not a user form.

The command button is built at design time, but the option buttons are
built by the user at run time, hence I cannot know what they are going
to be named ahead of time for any "if optionbutton1.value = true then"
code.

I need VBA to return to me the name of selected option button so I can
assign that name as a variable to use in a calling procedure in my
code.

--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Application.Caller syntax for worksheets?


Oooooh.

I didn't realize that they were different. Figured an option button
was an option button.

Thank you very much, lot of confusing frustrations suddenly make sense
now.


--
Ouka
------------------------------------------------------------------------
Ouka's Profile: http://www.excelforum.com/member.php...o&userid=23988
View this thread: http://www.excelforum.com/showthread...hreadid=502311

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
Application.Caller Marcelo Excel Discussion (Misc queries) 6 June 23rd 06 03:07 PM
Row = Application.Caller.Row Charles Woll Excel Worksheet Functions 8 February 28th 05 02:04 PM
Application.Caller Mark Worthington Excel Programming 9 February 12th 04 07:32 PM
application.caller Jase Excel Programming 0 January 6th 04 03:51 AM
Application.caller Clark B Excel Programming 2 July 29th 03 11:17 PM


All times are GMT +1. The time now is 06:28 AM.

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

About Us

"It's about Microsoft Excel"