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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
trying that gives
run-time error 104
unable to get the listboxes property of the worksheet class
 
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,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

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