LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.



 
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
Excel development tools? Neil Jones Excel Discussion (Misc queries) 1 April 22nd 10 09:24 PM
New Excel development ledgreg Excel Discussion (Misc queries) 2 February 27th 06 08:35 PM
Development tool,Excel,GUI BrianG Excel Discussion (Misc queries) 3 December 27th 04 02:05 PM
EXCEL MACRO DEVELOPMENT Joao Saraiva Excel Programming 1 January 23rd 04 10:35 AM
Development hours (off topic) Christian S. Snook Excel Programming 0 November 22nd 03 01:46 PM


All times are GMT +1. The time now is 12:31 AM.

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

About Us

"It's about Microsoft Excel"