Looping through open workbooks

JustPlainD

New Member
Joined
Sep 1, 2017
Messages
3
Hello,
I am trying to use loop for the first time. I need to loop through open workbooks, and close each workbook after I have copied the data from it. I am trying the following the below to indicate the next workbook, but it always treats the value as true even if there is only the workbook with the macros open.

If ActiveWindow.ActivateNext = False Then
GoTo DDC
ElseIf ActiveWindow.ActivateNext = True Then
GoTo DDC
End If

DC:
code here

DDC:
code to finalize.

I also tried

Do until ActiveWindow.ActivateNext = False

code

Loop

No luck there either.

Any help would be greatly appreciated.

JustPlainD
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi & welcome to the board
How about
Code:
For Each Wb In Workbooks
    MsgBox Wb.Name
Next Wb
 
Upvote 0
Thank you. I tried the code you recommended, and I see what it is doing, but I am not sure how to use it for looping at this stage of my excel developement.
 
Upvote 0
It is a loop.
as a better example
Code:
For Each Wb In Workbooks
    If Not Wb.Name = ThisWorkbook.Name Then
        ' code to
        ' do the
        ' copying
        ' goes here
        Wb.Close
    End If
Next Wb
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top