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
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