LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
mts mts is offline
external usenet poster
 
Posts: 1
Default User Input to open multiple files

Bob...I've seen a couple of your previous posts on opening multiple files.
I almost understand the code, but not quite.

My particular need involves opening several csv files from multiple folders.
one file at a time, i need to modify each file and then close each file as
an excel file (preferably in the same location as the csv file).

By the way, do you have any recommendations for any particular resources for
gaining ground in VBA (particularly for excel)?

Thank you.

Mike S.



"Bob Phillips" wrote in message
...
Sub ProcessFiles()
Dim FSO As Object
Dim i As Long
Dim sFolder As String
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object

Set FSO = CreateObject("Scripting.FileSystemObject")

sFolder = GetFolder
If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)

Set Files = Folder.Files
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
With ActiveWorkbook
.SaveAs Left(.FullName, Len(.FullName) - 4), _
FileFormat:=xlTextMac
.Close savechanges:=False
End With
End If
Next file

End If ' sFolder < ""

End Sub



'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name)
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long

If IsMissing(Name) Then Name = "Select a folder."
bInfo.pidlRoot = 0& 'Root folder = Desktop

bInfo.lpszTitle = Name

bInfo.ulFlags = &H1 'Type of directory to
Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog

'Parse the result
path = Space$(512)

GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If

End Function




--

HTH

RP

"Mike D." wrote in message
...
More than just a simple use of:

dim fileName as variant

fileName=application.GetOpenFilename("Excel Files(*.xls),
*.xls")

I would like to have the user indicate a whole folder. I
then need to open all of the files in that folder (which
are all going to be .xls files). I will then need to
open each file and copy certain info into a new
worksheet, with the result being a total of all the
collected data in this new worksheet.

I know how to open a known file and close it, etc. But,
my biggest problem is figuring out how to have the user
indicate the correct folder. I would also like the
prompt to "suggest" the path, e.g., C:\MyDocuments\Mar
2004.

Is this possible?





 
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
How to restrict user to input only one of multiple cells James Excel Worksheet Functions 1 August 28th 08 04:23 PM
Open multiple files into multiple worksheets of the same workbook lil Matt Excel Discussion (Misc queries) 1 October 31st 06 09:03 PM
Rollup of Data in Multiple Sheets (based on user input) Gauthier Excel Programming 1 December 10th 03 12:55 PM
Input Password to Open Linked Files Ricky Pang Excel Programming 0 August 2nd 03 04:55 AM
Input Password to Open Linked Files Ricky Pang Excel Programming 1 July 31st 03 05:29 AM


All times are GMT +1. The time now is 01:54 PM.

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"