PDA

View Full Version : Solved: ListBox ,select wbkb, open in Sub



omnibuster
02-03-2009, 02:54 PM
With ListBox , Selected Workbook opened correct, but when I put that "wbkb" in Sub.. I gived error:
Run-time error '424':
Object recuired


Private Sub Load_Click()
Dim wkbk As Workbook
'
'
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
Set wkbk = Application.Workbooks.Open( _
Filename:=.list(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=False)
wkbk.Activate
UserForm1.Hide
' Do something
Windows("Smpl.xls").Activate
'Do something

Call UUS ' Included: wbkb.Activate ???Error???

End If
Next i
End With
End Sub



Sub UUS()
wbkb.Activate ???
Range("A1").Select
ActiveSheet.Paste
End Sub


How resolved this problem?

lucas
02-03-2009, 03:52 PM
The sub UUS doesn't know what wbkb is.

You could activate it before you call UUS

Cosmo
02-03-2009, 04:35 PM
You can also send the wbkb as a parameter to the USS sub.
Sub UUS(wbkb)
wbkb.Activate ???
Range("A1").Select
ActiveSheet.Paste
End Sub


Private Sub Load_Click()
Dim wkbk As Workbook
'
'
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
Set wkbk = Application.Workbooks.Open( _
Filename:=.list(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=False)
wkbk.Activate
UserForm1.Hide
' Do something
Windows("Smpl.xls").Activate
'Do something

UUS (wbkb)

End If
Next i
End With
End Sub

omnibuster
02-04-2009, 10:16 AM
Thanks lucas & Cosmo, but this dont work.
Same error!

lucas
02-04-2009, 11:21 AM
You will need to upload your files so we can see if we can break it.....

clean it of any personal, etc. info and hit post reply..scroll down till you find Manage attachments.

omnibuster
02-04-2009, 11:59 AM
http://vbaexpress.com/forum/showthread.php?t=24856

Sry: Benzadeus (http://vbaexpress.com/forum/member.php?u=19707)

I upload this file before, but now dont see it?

omnibuster
05-04-2009, 01:42 PM
If .Selected(i) = True Then
Set wkbk = Application.Workbooks.Open( _
Filename:=.list(i, 0), _
Format:=xlCSV, _
Delimiter:=",", _
ReadOnly:=False)
' wkbk.Activate
filename1 = ActiveWorkbook.Name
ActiveWindow.Caption = "6625"
Windows("6625.xls").Activate
do som...


Windows("Smpl.xls").Activate