ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening a workbook based on a cell value (https://www.excelbanter.com/excel-programming/299524-opening-workbook-based-cell-value.html)

todd

Opening a workbook based on a cell value
 
Not sure if this is possible but here goes:

I need to be able to look through a column of cells and
open each workbook whose name corresponds to the value in
each cell one at a time. Example:

Column H
931C
941
921B
900B

In this example it would look at column H, open 931C.xls,
do some "stuff" (including closing the workbook after it's
done),open 941.XLS, do its "stuff", open 921B.xls....

The "stuff" I can handle, just have no clue how to loop
through the column and open the files like I described.
Any help would be GREATLY appreciated.



Chip Pearson

Opening a workbook based on a cell value
 
Todd,

Try something like

Dim Rng As Range
Dim WB As Workbook
For Each Rng In Range("H1:H100") ' << change range as needed
If Rng.Value < "" Then
Set WB = Workbooks.Open(ThisWorkbook.Path & "\" &
Rng.Value & ".xls")
' do something with WB
WB.Close SaveChanges:=True
End If
Next Rng


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




"Todd" wrote in message
...
Not sure if this is possible but here goes:

I need to be able to look through a column of cells and
open each workbook whose name corresponds to the value in
each cell one at a time. Example:

Column H
931C
941
921B
900B

In this example it would look at column H, open 931C.xls,
do some "stuff" (including closing the workbook after it's
done),open 941.XLS, do its "stuff", open 921B.xls....

The "stuff" I can handle, just have no clue how to loop
through the column and open the files like I described.
Any help would be GREATLY appreciated.





todd

Opening a workbook based on a cell value
 
Perfect...Thanks a million Chip
-----Original Message-----
Todd,

Try something like

Dim Rng As Range
Dim WB As Workbook
For Each Rng In Range("H1:H100") ' << change range as

needed
If Rng.Value < "" Then
Set WB = Workbooks.Open(ThisWorkbook.Path & "\" &
Rng.Value & ".xls")
' do something with WB
WB.Close SaveChanges:=True
End If
Next Rng


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




"Todd" wrote in

message
...
Not sure if this is possible but here goes:

I need to be able to look through a column of cells and
open each workbook whose name corresponds to the value

in
each cell one at a time. Example:

Column H
931C
941
921B
900B

In this example it would look at column H, open

931C.xls,
do some "stuff" (including closing the workbook after

it's
done),open 941.XLS, do its "stuff", open 921B.xls....

The "stuff" I can handle, just have no clue how to loop
through the column and open the files like I described.
Any help would be GREATLY appreciated.




.



All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com