VBA Loop to open other Workbooks based on cell information

Sin

New Member
Joined
Jan 24, 2009
Messages
32
Good Afternoon,

I have been searching through the forums, not found what I am looking for. If somebody knows of if this has been answered elsewhere, happy to go to that thread for the info.
My conundrum!
I have a worksheet that has a list of workbook names and locations. I need a piece of VBA code that will open the workbook based on the name in cell, I will get it to do something whilst it is open, then close the workbook, and cycle onto the next cell down to do the same again, until it finds a blank cell and stops.

Thanks a million for the help

Ash
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Does the column contain the full filepath & workbook name?
 
Upvote 0
In that case, how about
Code:
Sub SinTest()
   Dim Wbk As Workbook
   Dim Cl As Range
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      Set Wbk = Workbooks.Open(Cl.Value)
      ' do something here
      Wbk.Close [COLOR=#ff0000]False[/COLOR]
   Next Cl
End Sub
Change the False to True if you want to save the other workbook before closing it.
 
  • Like
Reactions: Sin
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,949
Messages
6,175,581
Members
452,653
Latest member
craigje92

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