LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Looping Open and Save as CSV



MCSDPhil

Hi there,
I had to have a go and see if I could do the iteration through files and
subfolders code and make it work. This seems to work ok.

Sub LoopThroughFiles()
'
' Keyboard Shortcut: Ctrl+c
'
Dim strBaseFolder As String
Dim strFolder As String
Dim intResult As Integer

'CHANGE THIS TO YOUR BASE FOLDER PATH
strBaseFolder = "C:\Documents and Settings\user\My
Documents\Personal\Tests\"

IterateFilesAndFolders strBaseFolder

End Sub

Function IterateFilesAndFolders(ByVal strFolder As String)
Dim strFileOrFolder As String
Dim colFolders As New Collection
Dim varSubFolder As Variant

Debug.Print "strFolder=" & strFolder
'Loop through files
strFileOrFolder = Dir(strFolder, vbDirectory)
Do While strFileOrFolder < ""
If strFileOrFolder < "." And strFileOrFolder < ".." Then
If (GetAttr(strFolder & strFileOrFolder) And vbDirectory) =
vbDirectory Then
Debug.Print ("Folder:" & strFileOrFolder & vbCrLf)
colFolders.Add strFileOrFolder, strFileOrFolder
Else
Debug.Print ("File:" & strFileOrFolder & vbCrLf)
If UCase(strFileOrFolder) = "VOLUME.XLS" Then
Debug.Print ("VOLUME.XLS Found" & vbCrLf)
'PUT YOUR OPEN AND SAVE CODE HERE
End If
End If
End If
strFileOrFolder = Dir()
Loop

For Each varSubFolder In colFolders
IterateFilesAndFolders strFolder & CStr(varSubFolder) & "\"
Next
End Function

The IterateFilesAndFolders function is called recursively, i.e. it is a
function that calls itself, to get at the files in the subfolders etc.

Regards, Phil.

*** Sent via Developersdex http://www.developersdex.com ***


 
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
workbook open in looping Patrick Molloy Excel Programming 1 July 27th 09 11:13 AM
Looping through list of workbooks to open & sheets to move Beverly Excel Programming 4 March 4th 08 08:16 PM
Looping thru open word documents to find a specific one dsimcox Excel Programming 1 August 8th 07 04:58 PM
Looping folder changing - Save Preview Picture Piranha[_50_] Excel Programming 2 October 2nd 05 12:33 PM
VBA code for looping through open workbooks and worksheets Jamie Martin[_2_] Excel Programming 1 July 24th 03 06:44 PM


All times are GMT +1. The time now is 03:38 AM.

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"