Solved

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

Posted on 2001-06-26
6
235 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Vlookup for IP 3 51
Excel 2016 - What is this arrow pointing to a cell? 9 58
Word - Access 3 29
Excel list clean up 6 44
Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

17 Experts available now in Live!

Get 1:1 Help Now