LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Quick file overwrite script

Here's some generic procs that drill for files in a specified folder
and any subfolders...


Sub DirDrillFldrs()
' Lists all files in a folder.
' Calls out to list all files in subfolders.

Dim vFldr, vFile, sTopFldr$

On Error GoTo Cleanup
sTopFldr = GetDirectory '//prompt user for parent folder
If sTopFldr = "" Then Exit Sub '//user cancels

Set vFldr =
CreateObject("Scripting.FileSystemObject").GetFold er(sTopFldr)
Debug.Print vFldr.Path
For Each vFile In vFldr.Files: Debug.Print vbTab & vFile.name: Next

DirDrillSubFldrs vFldr '//optionally drill each subfolder

Cleanup:
Set vFldr = Nothing
End Sub

Sub DirDrillSubFldrs(Folder)
' Lists all files in 'Folder'
' Recursively lists all subfolders/files

Dim vSubFldr, vFile, vFiles

On Error GoTo Cleanup
For Each vSubFldr In Folder.SubFolders
Debug.Print vSubFldr.Path

Set vFiles =
CreateObject("Scripting.FileSystemObject").GetFold er(vSubFldr.Path).Files

For Each vFile In vFiles: Debug.Print vbTab & vFile.name: Next
DirDrillSubFldrs vSubFldr
Next

Cleanup:
Set vFiles = Nothing
End Sub

Function GetDirectory$(Optional OpenAt, Optional Msg$)
' Returns the path of a user selected folder
' Note: By default, dialog opens at 'Desktop'
' Args:
' OpenAt Optional: Path to the dialog's top level folder
' Msg Optional: The dialog's title

If Msg = "" Then Msg = "Please choose a folder"
On Error Resume Next '//if user cancels
GetDirectory = CreateObject("Shell.Application").BrowseForFolder( 0,
Msg, &H40 Or &H10, OpenAt).Self.Path
End Function 'GetDirectory()

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


 
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
Excel File Overwrite GradAsh10 Excel Discussion (Misc queries) 1 January 18th 10 04:13 PM
how to save a file and overwrite existing file Daniel M Excel Programming 1 January 18th 08 07:45 PM
Prevent PivotTable Overwrite Warning and Disallow Overwrite jonahviakeyboard Excel Programming 0 November 27th 07 05:08 PM
Overwrite saved workbook in VB Script Martin X. Excel Programming 2 August 13th 07 03:46 PM
Say 'YES' to overwrite file Mike G. Excel Programming 6 June 1st 04 06:58 PM


All times are GMT +1. The time now is 10:31 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"