How to refer to a listbox

  • Thread starter Thread starter Geof Wyght
  • Start date Start date
G

Geof Wyght

Hello,
I have a listbox on a worksheet. I know how to refer to it
from the worksheet module that it's in:
Me.listTasks.ListIndex = -1
but how would I refer to it from another module?
Thanks.
Geof.
 
Yes, that helped, thanks.
For some reason, this did not work:
wksDash.listTasks.ListIndex = -1
where:
Set wksDash = ThisWorkbook.Worksheets("Dashboard")

But this did:
ThisWorkbook.Worksheets("Dashboard").listTasks.ListIndex
= -1

Geof.
 
I didn't have any problem with it:

set sh = Thisworkbook.Worksheets("Sheet1")
? sh.Listbox1.Value
DDDD
? sh.Listbox1.ListIndex
3

Maybe you had a typo.
 
Perhaps, but this won't even compile:
'Calls: SetRefs
Private Sub Workbook_Open()
Call SetRefs 'Declare global objects.
wksDash.Activate
'The next line works, but it's commented out.
'ThisWorkbook.Worksheets("Dashboard").listTasks.ListIndex
= -1
'Method or data member not found (listTasks).
wksDash.listTasks.ListIndex = -1
End Sub

Geof.
 
pasted this into thisworkbook

Private Sub Workbook_Open()
Call SetRefs 'Declare global objects.
wksDash.Activate
'The next line works, but it's commented out.
'ThisWorkbook.Worksheets("Dashboard").listTasks.ListIndex= -1
'Method or data member not found (listTasks).
wksDash.listTasks.ListIndex = -1
End Sub

created a dummy procedure SetRefs in a general module and it compiled fine
for me. And I don't have a listbox named ListTasks or a sheet named
Dashboard.
 
I believe you. I guess I'll come back to it later since
the complete object hierarchy reference is working. Thanks.
Geof.
-----Original Message-----
pasted this into thisworkbook

Private Sub Workbook_Open()
Call SetRefs 'Declare global objects.
wksDash.Activate
'The next line works, but it's commented out.
'ThisWorkbook.Worksheets
("Dashboard").listTasks.ListIndex= -1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top