Here's the script for a userform to print selected active worksheets. It allows me to do select worksheets...it even prints them out just like I want.....but then it throws error 381 "could not get list property. Invalid property array index"
I've tried putting "on error resume next" right above the offending line but that somehow causes it to print 9 copies.
Any suggestions?
I've tried putting "on error resume next" right above the offending line but that somehow causes it to print 9 copies.
Any suggestions?
Code:
Private Sub CommandButton1_Click()
For x = 0 To Sheets.count - 1
On Error Resume Next
shtname = UserForm1.ListBox1.List(x, 0) 'error occurs here as the documents are printing it seems
If UserForm1.ListBox1.Selected(x) Then
Worksheets(shtname).Activate
ActiveSheet.PrintOut copies:=2
End If
Next x
UserForm1.Hide
Sheets("master").Activate
End Sub
Private Sub UserForm_Initialize()
Dim sht As Worksheet
ListBox1.Clear
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible = xlSheetVisible Then
ListBox1.AddItem sht.Name
End If
Next sht
Me.Height = 128
End Sub