Solved

Reading values by VBA of ComboBoxes/Textfields which are included directly in a table sheet

Posted on 2001-06-26
6
239 Views
Last Modified: 2012-06-21
Hi Experts,

how can I read the values of ComboBoxes,Textfields and other Objects, when they are included directly in an Excel sheet ?

It should start with ThisWorkbook.Sheets(1). ???

Thanks for the help

FFengler
0
Comment
Question by:FFengler
  • 4
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
cri earned 50 total points
ID: 6228438
Do you use Forms or Control Toolbox objects ?

For _Forms_ calacuccia answered this for me once in
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=msoffice&qid=10352410:

xxxxxxxxxxxxx

Ctrl defines the name of the form to be analysed, description = 1 will tell  if the choosen item in the ListBox or ComboBox has to be displayed instead of the value. The value of Description is negliged for CheckBox and OptionButton forms.

Function MyRet(Ctrl As String, Description As Boolean)
Dim mctr As Shape

Application.Volatile 'Only if used from worksheet side
Set mctr = ActiveSheet.Shapes(Ctrl)

If mctr.Type <> msoFormControl Then Exit Function

Select Case mctr.FormControlType
   
   Case xlListBox
   If Description = 0 Then
       MyRet = mctr.ControlFormat.Value
   Else
       MyRet = ActiveSheet.Range(mctr.ControlFormat.ListFillRange).Cells(mctr.ControlFormat.Value)
   End If

   Case xlDropDown
   If Description = 0 Then
       MyRet = mctr.ControlFormat.Value
   Else
       MyRet = ActiveSheet.Range(mctr.ControlFormat.ListFillRange).Cells(mctr.ControlFormat.Value)
   End If

   Case xlCheckBox
   If mctr.ControlFormat.Value = -4146 Then
       MyRet = True
   Else
       MyRet = False
   End If

   Case xlOptionButton
   If mctr.ControlFormat.Value = -4146 Then
       MyRet = True
   Else
       MyRet = False
   End If

End Select

End Function
0
 

Author Comment

by:FFengler
ID: 6231252
Hello cri,

I included your Function into my Code. When I tried to read the value of a Checkbox which is directly included in a Sheet, I get an error within your function because the Checkbox  cannot be found.

The call of the function is as follows:

 s.verz = MyRet("VerzeichnisBox", False)

"VerzeichnisBox" is the name of the Checkbox
I changed the function to refer to a special Sheet in the workbook:

Instead of
Set mctr = ActiveSheet.Shapes(Ctrl)

I use
   
Set mctr = ThisWorkbook.Sheets("Allgemein").Shapes(Ctrl)

which should also work.


where's the mistake here ?

Thanks
0
 
LVL 13

Expert Comment

by:cri
ID: 6232377
Sorry to re-ask: Do you use Forms or Control Toolbox objects ?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:cri
ID: 6232381
If unsure, check under View|Toolbar
0
 

Author Comment

by:FFengler
ID: 6242091
Hi cri,

I am using Control Toolbox objects (out of the control Toolbox) which I put directy into a table sheet, I am not using a form for this.

0
 
LVL 13

Expert Comment

by:cri
ID: 6243025
As stated in my post of 06/26/2001 the code reads the values for Form _objects_. These are the predecessors of the ActiveX bloats. I use nothing else.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Some time ago I was asked to create a VBA function that would calculate a check digit for an input number, using the following procedure: First, sum up all the individual digits in the number If that sum value has more than one digit, then sum up …
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now