Excel VBA - Help looping through all but 2 workbooks

W

waveracerr

I need to loop through all workbooks except two that I specify. I hav
the code to loop through all workbooks except the workbook containin
the code but I cannot modify the code to include a second workbook th
code should skip.

Sub test()
Dim wb As Workbook

Application.DisplayAlerts = False

'Loop through each open workbook
For Each wb In Workbooks
If Not (wb.Name = ThisWorkbook.Name) Then
wb.Activate
Range("H10") = "CHECK"
End If
Next wb
End Sub

I tried replacing the If statement with:
If Not (wb.Name = ThisWorkbook.Name) Or (wb.Name = "test.xls"
Then

....with no luck.

Thanks for any assistance
 
C

Chip Pearson

Try

If (wb.Name <> ThisWorkbook.Name) And (wb.Name <> "test.xls")
Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top