Solved

911!  How do I get a reference to a radio button (Groupbox) object in excel spreadsheet macro?

Posted on 2001-06-19
7
286 Views
Last Modified: 2010-05-02
Hi all,

    OK I am desperate now!  I am an OK Java and ASP developer, but in this project I am using JNI-COM bridge to MS Excel COM object excel9.olb I think.  Anyway, our client wants to use thei exisisting desktop excel spreadsheet app w/ macros with our java web app.  I have a GroupBox ("GroupBox14") on a Worksheet (Worksheet"AppData") which seems to be bound to the value of a range on another worksheet i.e Worksheet("Options").Range("A1B1").Value.  So if GroupBox14 has 3 radio buttons, "Small", "Medium", and "Large", the values 1,2,and 3 in A1B1 would respectively be small, medium and large.
     Are you with me so far?  OK, I am having a hard time setting the value of the radio buttons via setting the value in A1B1.  I want to get a reference to the GroupBox14 object and do soemthing like:
    Worksheet("AppData").GroupBox14.Value := 2
But I can't figure out the proper syntax within code editor or help menu.  I only have VB5 IDE installed, maybe I need VB6?  I searched MS site and Google but cant find syntax as Excel has some ambiguous stuff.
    How the heck can I do this?  I will give MAX points for any help!  Thanks!

 
0
Comment
Question by:posconsultant
7 Comments
 
LVL 7

Expert Comment

by:q2eddie
ID: 6209223
Hi, posconsultant.

You might be better off testing the values of the radio buttons within the group themselves.  Seems dumb, but I ran into the same problem that you did.  There does not seem to be a property on the shape itself to determine what the value was.

If Worksheet("AppData").OptionButton1.Value Then
  lcValue = "Small"
End If
If Worksheet("AppData").OptionButton2.Value Then
  lcValue = "Medium"
End If
If Worksheet("AppData").OptionButton3.Value Then
  lcValue = "Large"
End If

Leave this question open.  Perhaps, someone else will have a better suggestion.

Bye. -e2
0
 
LVL 3

Accepted Solution

by:
daffyduck14mil earned 150 total points
ID: 6210249
Ok,

I think I can help you out. I have assumed that you have not used the Microsoft.Forms2 controls, but rather the "Control elements" that is used on the worksheets so often (they are transparent) right?

Now, if that is the case, it is not possible to access the control using your method Eddie. Excel sees those optionbuttons as shapes. Yes, shapes. So, in order to access a shape called optionbutton14 you have to use the shapes layer of the excel sheet. In the code that I give here, you can test if they are shapes or, genuine controls:

    Dim wxs As Worksheet
    Dim object As OLEObject
    Dim oShape As Shape
   
    Set wxs = Worksheets(1)
   
    For Each object In wxs.OLEObjects
        MsgBox "Oleobject: " & object.Name
    Next
   
   
    For Each oShape In wxs.Shapes
        MsgBox "Shape: " & oShape.Name
    Next

    'wxs.Shapes("Option Small").ControlFormat = 1

Make a new macro in your sheet, and put this code in. Run it from the Visual Basic editor in Excel. I have assumed that the controls are on the first sheet in the workbook.

Now, when you get a "Shape: Optionround x" message, then you know how to access the controls. Replace the "Option Small" with the name that you got from the messagebox. So, for example: If you run the code and you get back a "Shape: Optionround 2" message, put the "Optionround 2" in the line. and run the macro again.

If it is a shape, then you will see that running the macro will select the option in the groupbox. A word about the controlformat: 1 means selected, 0 means it's not selected.

You can then use simple logic (case statement) to evaluate the value of another cell and act accordingly.

If you need any help, or additional information, just say.

Grtz.©

D.
0
 

Author Comment

by:posconsultant
ID: 6211845
Thanks to both!  I'll try your suggestions tomorrow at work.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 49

Expert Comment

by:DanRollins
ID: 7139562
Hi posconsultant,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Split points between: q2eddie and daffyduck14mil

posconsultant, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 7139820
Perhaps he has workdays that last 1 and a half year?

:)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140075
late sleeper -;)
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7181622
Per recommendation, force-accepted.

Netminder
CS Moderator

q2eddie: points for you at http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328653
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 94
VBA filters 2 62
Advice in Xamarin 21 80
Create Files based on Cell Values in a Range in Excel 12 42
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question