ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening Multiple Files (https://www.excelbanter.com/excel-programming/317188-opening-multiple-files.html)

mike s

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.




Dave Peterson[_5_]

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

mike s

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





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

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