Error 424: Object required

inetkemp

New Member
Joined
Sep 2, 2011
Messages
13
I get 'Error 424: Object required', and I can´t figure out why. I have a listbox named ListBoxforPrint in the Worksheet (not a userform). SmainMenu is the CodeName of the sheet. Can you please help? Tx

Sub PrintSelected() 'Print the selected sheets from a multiSelect listbox
Dim i As Long
Dim Msg As String


delOldPrintList
listNo = 1

SMainMenu.Activate
With SMainMenu.ListBoxforPrint
For i = 0 To .ListCount - 1

If .Selected(i) Then
listNo = listNo + 1
SSysSheet.Cells(listNo, 6).Value = .List(i)
MyShName = SSysSheet.Cells(listNo, 6).Value
Worksheets(MyShName).PrintOut
End If
Next i
End With

If listNo = 1 Then
Msg = "No items selected to print"
MsgBox Msg
End If

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
tx Peter. Its working now, but then I get the next error
runtime error 1004
unable to get the selected property of the Listbox class
 
Upvote 0
A Form control ListBox items count starts from 1. This worked for me

Code:
Sub atest()
Dim i As Long
With ActiveSheet.ListBoxes("List Box 1")
    For i = 1 To .ListCount
        If .Selected(i) Then MsgBox i
    Next i
End With
End Sub
 
Upvote 0
Try this:
Code:
Sub PrintSelected()    'Print the selected sheets from a multiSelect listbox
Dim I As Long
Dim Msg As String
Dim lst As Object
 
    listNo = 1
    Set lst = SMainMenu.OLEObjects("ListBoxforPrint").Object
    
    With lst
        For I = 0 To .ListCount - 1
            If .Selected(I) Then
                listNo = listNo + 1
                SSysSheet.Cells(listNo, 6).Value = .List(I)
                MyShName = SSysSheet.Cells(listNo, 6).Value
                Worksheets(MyShName).PrintOut
            End If
        Next I
    End With
    If listNo = 1 Then
        Msg = "No items selected to print"
        MsgBox Msg
    End If
End Sub
 
Upvote 0
How have you created this listbox?

The code I posted is for an ActiveX listbox not a Forms listbox.

I've tried various things to get Selected with the latter but nothing has worked, so far.

Have you considered trying an ActiveX listbox?
 
Upvote 0
Hi Norie
I used the developer tab and dragged the listbox on the worksheet.
in the top left corner I named the sheet
I dont want to use an axtivex control
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top