PDA

View Full Version : process array of excel files not working



lawrencef
01-07-2009, 02:00 PM
hi, I have some VBA code that I use to process an array of CSV files. I originally got this code from “Mastering Excel 2003”. It worked fine for about a year (with xp) then suddenly it has started to work only intermittently. Now it hardly works at all.

INFO
Version – I've tried using on xp and also on vista – generally doesn't work at all anymore on xp but occasionally works on vista (usually after shutdown and restart)
What I want it to do – get the function “GetEXcelFiles” to recognize that I've selected an array of CSV files so I can process them in the main part of my script
Problem – most of the time the function “GetExcelFiles” fails to recognise that I've selected an array of CSV files and the sub exits ie the multiselect part of this function doesn't seem to work consistently

Can anyone help?????


CODE

Sub ProcessANZFileBatch()
Dim nIndex As Integer
Dim vFiles As Variant
Dim wb As Workbook
Dim wsname As String
Dim adr1 As String
Dim bAlreadyOpen As Boolean
Dim ws As Worksheet

vFiles = GetExcelFiles("Select Workbooks for Processing")

' Make sure the dialog wasn't cancelled - in which case vFiles would equal False and therefore wouldn't be an array.
If Not IsArray(vFiles) Then
Debug.Print "No files selected."
Exit Sub
End If

' OK - loop through the filenames

For nIndex = 1 To UBound(vFiles)
Code to process each file goes here …….



Function GetExcelFiles(sTitle As String) As Variant
GetExcelFiles = Application.GetOpenFilename(Title:=sTitle, MultiSelect:=True)
End Function

lucas
01-07-2009, 03:50 PM
http://www.vbaexpress.com/forum/showthread.php?t=22581