PDA

View Full Version : Solved: Compile Error loop without do



farrukh
05-29-2011, 02:11 AM
Dear All,

Help me i am trying to make a code but get error "Compile Error loop without do"

Sub test()
Dim strFile As String, strFolder As String
Dim wb As Workbook, ws As Worksheet

strFolder = "c:\temp\"

strFile = Dir(strFolder & "*.xl*", vbNormal)
Do While strFile <> ""
Set wb = Workbooks.Open(strFolder & strFile)
Set ws = wb.Sheets(2)
For Each wb In wb.Worksheet

' For Each strFile In wb.Files

If wb.strFile Like "*.xls*" Then
'Your current code here with the below changes
ws.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ws.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
ws.Range("A1") = Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
End If
End If
Exit Sub


wb.Close True
strFile = Dir
Loop
'End If
End Sub

Regards,
farrukh

Chabu
05-29-2011, 02:22 AM
you forgot the closing "Next" of the for each loop

farrukh
05-29-2011, 02:27 AM
Dear Chabu,

It runs now i am doing some thing wrong there please advise

For Each wb In wb.Worksheet
If wb.strFile Like "*.xls*" Then


Thanks
Farrukh

Bob Phillips
05-29-2011, 02:47 AM
Try



For Each wb In wb.Worksheet
If wb.Name Like "*.xls*" Then

farrukh
05-29-2011, 03:01 AM
I have got error

"Object does not support this property or method"

For Each wb In wb.Worksheet
:dunno
Thanks
Farrukh

Bob Phillips
05-29-2011, 03:16 AM
That should be



For Each ws in wb.Worksheets

farrukh
05-29-2011, 03:21 AM
Dear xld,

Thanks alot it works perfectly...:thumb

Regards,
farrukh