Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Help looping through all but 2 workbooks

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

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Excel VBA - Help looping through all but 2 workbooks

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


"waveracerr " wrote
in message ...
I need to loop through all workbooks except two that I specify.

I have
the code to loop through all workbooks except the workbook

containing
the code but I cannot modify the code to include a second

workbook the
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!


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through 2 workbooks Pierre Excel Discussion (Misc queries) 3 March 7th 08 04:00 PM
Looping through all workbooks Mervyn Thomas[_3_] Excel Programming 0 July 31st 03 05:50 PM
Looping through all workbooks Mervyn Thomas[_3_] Excel Programming 0 July 29th 03 02:59 PM
Looping through all workbooks Abdul Salam[_3_] Excel Programming 1 July 29th 03 02:59 PM
VBA code for looping through open workbooks and worksheets Jamie Martin[_2_] Excel Programming 1 July 24th 03 06:44 PM


All times are GMT +1. The time now is 03:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"