Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening Multiple Files
I am trying to use a form that will allow me to select between three
different options of events: Opening a single csv file, or Opening multiple csv files from different locations, or Open all csv files from multiple locations. Then....I need to modify each file, one at a time, Then...close each file as an excel file (preferably in the same location as the csv file). (Ultimately, I could move all the files into one folder as a temporary work-around, but this wouldn't be my preference). I am not sure how to code the later two options. Any help would be greatly appreciated. Mike S. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening Multiple Files
If you process all the files the same way, maybe displaying the file open dialog
until they hit cancel would work. They can change to as many folders and select as many .csv files as they need. Option Explicit Option Base 1 Sub testme() Dim myFileNames As Variant Dim AllMyFileNames() As String Dim iCtr As Long Dim TotalFiles As Long ReDim AllMyFileNames(1 To 1) TotalFiles = 0 Do myFileNames = Application.GetOpenFilename _ (filefilter:="CSV Files, *.csv", MultiSelect:=True) If IsArray(myFileNames) Then TotalFiles = TotalFiles + UBound(myFileNames) ReDim Preserve AllMyFileNames(1 To TotalFiles) For iCtr = UBound(myFileNames) To 1 Step -1 AllMyFileNames(TotalFiles + 1 - iCtr) = myFileNames(iCtr) Next iCtr Else Exit Do End If Loop If TotalFiles = 0 Then MsgBox "try later!" Exit Sub End If For iCtr = 1 To TotalFiles MsgBox AllMyFileNames(iCtr) 'Workbooks.Open AllMyFileNames(iCtr) Next iCtr End Sub Tell your users that they can select all the csv files in a folder by hitting ctrl-a in that file|open dialog. (Excel seems to just ignore selected folders when you do this.) mike s wrote: I am trying to use a form that will allow me to select between three different options of events: Opening a single csv file, or Opening multiple csv files from different locations, or Open all csv files from multiple locations. Then....I need to modify each file, one at a time, Then...close each file as an excel file (preferably in the same location as the csv file). (Ultimately, I could move all the files into one folder as a temporary work-around, but this wouldn't be my preference). I am not sure how to code the later two options. Any help would be greatly appreciated. Mike S. -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Opening Multiple Files
Hi Dave...
this option can work when I wouldn't have to go into too many folders...however, sometimes I'll have up to a hundred+ Thanks for your input. Mike S. "Dave Peterson" wrote in message ... If you process all the files the same way, maybe displaying the file open dialog until they hit cancel would work. They can change to as many folders and select as many .csv files as they need. Option Explicit Option Base 1 Sub testme() Dim myFileNames As Variant Dim AllMyFileNames() As String Dim iCtr As Long Dim TotalFiles As Long ReDim AllMyFileNames(1 To 1) TotalFiles = 0 Do myFileNames = Application.GetOpenFilename _ (filefilter:="CSV Files, *.csv", MultiSelect:=True) If IsArray(myFileNames) Then TotalFiles = TotalFiles + UBound(myFileNames) ReDim Preserve AllMyFileNames(1 To TotalFiles) For iCtr = UBound(myFileNames) To 1 Step -1 AllMyFileNames(TotalFiles + 1 - iCtr) = myFileNames(iCtr) Next iCtr Else Exit Do End If Loop If TotalFiles = 0 Then MsgBox "try later!" Exit Sub End If For iCtr = 1 To TotalFiles MsgBox AllMyFileNames(iCtr) 'Workbooks.Open AllMyFileNames(iCtr) Next iCtr End Sub Tell your users that they can select all the csv files in a folder by hitting ctrl-a in that file|open dialog. (Excel seems to just ignore selected folders when you do this.) mike s wrote: I am trying to use a form that will allow me to select between three different options of events: Opening a single csv file, or Opening multiple csv files from different locations, or Open all csv files from multiple locations. Then....I need to modify each file, one at a time, Then...close each file as an excel file (preferably in the same location as the csv file). (Ultimately, I could move all the files into one folder as a temporary work-around, but this wouldn't be my preference). I am not sure how to code the later two options. Any help would be greatly appreciated. Mike S. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
MULTIPLE FILES OPENING | New Users to Excel | |||
opening multiple files into one workbook, but multiple worksheets.... | Excel Discussion (Misc queries) | |||
opening multiple .txt files from multiple folders | Excel Discussion (Misc queries) | |||
How can I view files chronologically when opening multiple files | Excel Discussion (Misc queries) | |||
opening multiple .csv files from the web | Excel Programming |