ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A development of a Macro by Tom (https://www.excelbanter.com/excel-programming/305580-re-development-macro-tom.html)

Tom Ogilvy

A development of a Macro by Tom
 
Sub workbookopen()
Dim rng As Range, cell As Range
Dim sStr As String, sStr1 As String
Dim sPath As String
Dim sArrPath(1 to 2) as String
Dim rngArr(1 to 2) as Range
Dim wkbk As Workbook
sArrPath(1) = "F:\mydir1\mydir2\"
sArrPath(2) = "C\Myfiles\"
With Worksheets("List")
Set rngArr(1) = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
With Worksheets("List2")
Set rngArr(2) = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With

for i = 1 to 2
sPath = sArrPath(i)
set rng = rngArr(i)

For Each cell In rng
sStr = cell.Value
sStr1 = Dir(sPath & sStr & "*.xls")
If sStr1 < "" Then
Set wkbk = Workbooks.Open(sPath & sStr1)
End If
Next cell
Next i
End Sub

--
Regards,
Tom Ogilvy


"Starting to Program" wrote in
message ...
The following macro was written by Tom, I wondered if anyone (Tom?)
could help in extending it?

What I need to do is instead of having 1 list of files I need 2 (as in

different directories)

Can anyone help.

The Macro (that works for one list is below...)

Sub workbookopen()
Dim rng As Range, cell As Range
Dim sStr As String, sStr1 As String
Dim sPath As String
Dim wkbk As Workbook
sPath = "F:\mydir1\mydir2\"
With Worksheets("List")
Set rng = .Range(.Cells(2, 1), .Cells(2, 1).End(xlDown))
End With
For Each cell In rng
sStr = cell.Value
sStr1 = Dir(sPath & sStr & "*.xls")
If sStr1 < "" Then
Set wkbk = Workbooks.Open(sPath & sStr1)
End If
Next
End Sub

Thanks.




Starting to Program[_2_]

A development of a Macro by Tom
 
Tom,

Many thanks for your prompt reply.

Thanks again


All times are GMT +1. The time now is 10:00 AM.

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