473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Excel 2007 - Listbox "Selected()" property fails

I am having a problem trying to select items from a listbox that is drawn on my worksheet. I have no problem adding items, or removing items.... only when I try to identify the items that are selected.

There is no ".Selected" in the intellisense for either the object directly, or the object.ControlFormat. When I execute this code, Excel fails with the error message: "Runtime Error 438. Object doesn't support this property or method."

I've scoured the net looking for help, but couldn't find any that addressed this issue.

Anybody have insight on how to either fix the problem or a workaround where I can see what items are selected and dump them into a collection?

' I tried all three modes of the listbox (single, multi, extended - select), which is available when right-clicking the control.

Expand|Select|Wrap|Line Numbers
  1.     ' Dimension variables and objects
  2.         Dim ws As Excel.Worksheet
  3.         Dim lst As Shape
  4.         Dim cList As Collection         ' The index of the "Selected" currencies
  5.         Dim i As Integer                ' Loop variable
  6.  
  7.     ' Set objects
  8.         Set ws = Application.Sheets(MAIN_SHEET)
  9.         Set lst = ws.Shapes("lstCurrencies")
  10.         Set cList = New Collection
  11.  
  12.     ' Set the Selected Items
  13.         With lst.ControlFormat
  14.             For i = 1 To .ListCount
  15.                 If .Selected(i) Then            ' <----  FAILS HERE
  16.                     cList.Add lst.ControlFormat.List(i)
  17.                     .Selected(i) = False
  18.                 End If
  19.             Next i
  20.         End With
  21.  
Feb 5 '10 #1

✓ answered by Guido Geurs

dear,

this works in Office 2003:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton2_Click()
  2. Dim i As Integer
  3. Dim data As String
  4.    For i = 0 To ListBox1.ListCount - 1
  5.       If ListBox1.Selected(i) Then data = data & ListBox1.List(i) & "-"
  6.    Next
  7.    TextBox1.Text = data
  8. End Sub
see attachment

br,

5 6363
Guido Geurs
767 Expert 512MB
dear,

this works in Office 2003:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton2_Click()
  2. Dim i As Integer
  3. Dim data As String
  4.    For i = 0 To ListBox1.ListCount - 1
  5.       If ListBox1.Selected(i) Then data = data & ListBox1.List(i) & "-"
  6.    Next
  7.    TextBox1.Text = data
  8. End Sub
see attachment

br,
Attached Files
File Type: zip EXCEL data from listbox_v1.zip (12.8 KB, 296 views)
Feb 5 '10 #2
Yes, but unfortunately not in the version I'm using (2007). Maybe it's a library I don't have installed (or the order that the libraries are listed)? Or just reduced functionality or transversed into something else? Or maybe the way I dim'd the object as shape? Not sure, but it's driving me nuts! And thanks for all your help recently with everything, much appreciated.
Feb 5 '10 #3
Guido Geurs
767 Expert 512MB
dear,

Is my attachment running in 2007 ?

br,
Feb 5 '10 #4
Ahh, I didn't even see the attachment, and yes it is working!

I see that you used the ActiveX listbox, and not the Form listbox. The ActiveX listbox methods were available in the code-behind for the sheet, but for me I was unable to access it in a module.

I have a few things to work backwards from to get things working properly now.

Thanks ggeu, you've saved the rest of my hair, as I didn't get a chance to pull all of it out yet!
Feb 6 '10 #5
Well I don't know what it was, but I still couldn't get it to work in my workbook. It worked in a new XL07 workbook, but not the one I was working on.

What I did was export all the modules, form and code to a new workbook, testing the functionality between each import.

And it works in the new workbook that contains all of the code and copied sheets.

I notice that there are two dll libraries that I didn't reference in the new workbook, so maybe it's either one of those that was conflicting, or it was a setting in the options of the workbook. Who knows, but without your help I would have never figured this one out.

Thanks again!
Feb 6 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
4
by: charliewest | last post by:
I need to set the selected drop down list value at run time. I am aware of the method "SelectIndex" however this works only if you know the precise location of the value within the ListItem...
2
by: Nathan Sokalski | last post by:
I have several DropDownList controls on my page that use databinding. However, I want to give users the option of selecting a choice such as "None Selected" or something else that shows they did...
0
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
0
by: tom c | last post by:
In ASP.Net 1.1, the selected property of the list box is not working for me. In the code below, I loop through all the items in a listbox. I can see the text and value from the list box just as I...
0
by: Piotr Strycharz | last post by:
Hi, Here is my situation: I have disabled CheckBoxList. This CheckBoxList (actually: all of the checkboxes) is being enabled by user using javascript code. Than - user can select some of the...
2
by: lord.zoltar | last post by:
Hello I'm trying to programmatically set a listbox to have several items selected when it is loaded. Which items are selected is based on a saved user setting. Right now, I'm trying:...
3
by: softengg | last post by:
Hi, I am using C#.Net Win Apps and I want to get the ID values which is bind to a listbox thru a loop???? ie. listbox's selectedvalue property.......? how it is possible to get all the selected...
2
by: alexandis | last post by:
I have menu bound to sitemap file. This is a piece of code <asp:menu ... > <StaticItemTemplate> <%# ((MenuItem)Container.DataItem).Selected ? : %> </StaticItemTemplate> </asp:menu> I check...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.