Thread: Flling an array
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Adri[_2_] Adri[_2_] is offline
external usenet poster
 
Posts: 14
Default Flling an array

Ron de Bruin wrote:
| Hi Adri
|
| You can select the files you want with the CTRL key down
| If you use CTRL-A in the dialog you select all the files
|
| Fname is the Array of the selected files
|
| You can loop through the files in the Array with this
| For N = LBound(FName) To UBound(FName)
|
| I use open the files as a example but you can do what you want.
|
| What do you want to do with the files in the Array?
| Maybe we can give you a better answer then
|
Hi Ron,
I have this code (from the internet). It copies the contence of the seprate
files to one workbook .
To prevent a lot of typing (the file are at a network server with long
names) I want to use the macro to fill the array.
I hope you understand the problem now.


Option Explicit
Sub GetData()

Dim myWorkbooks As Variant
Dim myFolder As String
Dim testStr As String
Dim newWkbk As Workbook
Dim tempWkbk As Workbook
Dim wCtr As Long

myFolder = "D:\Temp"
If Right(myFolder, 1) < "\" Then
myFolder = myFolder & "\"
End If

Set newWkbk = Workbooks.Add(1)
ActiveSheet.Name = "DummyToDelete"

myWorkbooks = Array("file1.xls", "file2.xls", "file4.xls")

For wCtr = LBound(myWorkbooks) To UBound(myWorkbooks)
testStr = ""
On Error Resume Next
testStr = Dir(myFolder & myWorkbooks(wCtr))
On Error GoTo 0
If testStr = "" Then
MsgBox myWorkbooks(wCtr) & " Is missing!" & vbLf & _
"Processing stopped"
Exit Sub
End If

Set tempWkbk = Workbooks.Open(Filename:=myFolder &
myWorkbooks(wCtr), _
ReadOnly:=True)

tempWkbk.Worksheets(1).Copy _
after:=newWkbk.Worksheets(newWkbk.Worksheets.Count )

tempWkbk.Close savechanges:=False

Next wCtr

Application.DisplayAlerts = False
newWkbk.Worksheets("DummyToDelete").Delete
Application.DisplayAlerts = True

Call RenSheets
End Sub