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
 
You do exactly the same with ActiveX controls.

Why don't you want to use one?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Well I can't see a way for that code to work with a Forms listbox.

Hopefully I'm missing something really obvious and someone else will spot it.:)
 
Upvote 0
I know what it is, or what it's not.

It isn't 0-indexed it's 1-indexed.

This worked, kind of stripped it down a bit though so you'll need to add the rest of your code.

Any problems post back.
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 = Worksheets("Sheet1").ListBoxes("List Box 3")  '.OLEFormat.Object
 
    With lst
        For I = 1 To .ListCount
            If .Selected(I) Then
                Debug.Print .List(I)
            End If
 
 
        Next I
    End With
 
End Sub

PS You can use the code name, it works but I'd tried Worksheets in the above version.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,225
Messages
6,129,604
Members
449,520
Latest member
TBFrieds

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