![]() ![]() ReDim Preserve flNames(UBound(flNames) + 1)įlNames(UBound(flNames)) = Folder & vbTab & _ĪFile.Name & vbTab & aFile.Size & vbTab & aFile. Selection.ConvertToTable Separator:=wdSeparateByTabs, AutoFitBehavior:=wdAutoFitFixed "Size" & vbTab & "Creation Date" & vbCrLf Selection.TypeText "Path" & vbTab & "File name" & vbTab & _ ![]() Set FileSystem = CreateObject("Scripting.FileSystemObject") ' ***** This declaration must be at the top of the module ***** Word’s Sort can then be used to sort into any order. The results are put into a table in a new document. Other file information could be shown by changing the statement flNames(UBound(flNames)) = … The detail given for each file is the path, the name, the size and the creation date. The following macro will produce a list of all files in a folder and its sub-folders. The solution shown will give a list of files in a folder but not its sub folders. ![]() There are also third-party solutions available, such as Karen's Directory Printer, which was suggested by more than one subscriber: If you are looking for a more traditional way of getting the list using the command prompt or a macro, you should consider the WordTip located at this URL: For instance, you might want to select what was pasted and use Find and Replace to modify the path to each file, as desired. You can then edit the list in any way desired. What you end up with is the list of files-including full path names-in your document. Press Ctrl+V to paste the contents of the Clipboard.You can choose from a hierarchical folder view or a list of favorite folders. Make sure the insertion point is where you want the list of file contents added. On the 'Directory' tab, choose the directory for which you want to list the contents.Context menu displayed when Shift+right-clicking on a group of files. While holding down the Shift key, right-click on one of the selected files.Everything in the folder should now be selected. Using File Explorer, navigate to the folder whose contents you want to list.Windows immediately opens a File Explorer window. (This makes sure that your Word document is not active.) Click on the Desktop, outside of Word.Choose where you want to search below Search Search the Community. ![]() Here's an easy way that I use all the time: Top Contributors in Windows 7: Bill Smithers - LemP - Canadian Tech. You can find 'tree.doc' created in the same folder. Above command will make the folder and files structure recursively and export to word document file. Then run the following command to generate. She wonders if there is an easy way to get such a list in Word.Īctually, there are a few ways you can accomplish this task, but none of them are native to Word. Open command prompt window -> Go to your directory path. SelectedItems( 1 ) & "\" Else MsgBox "File selection cancelled!", vbCritical GoTo ExitSub_ End If End With ' ' sTargetFile = Dir(sTargetPath & cFileFilter, vbNormal + vbReadOnly) 'Loop through each Excel file in folder Do While sTargetFile vbNullString Set oWB = Workbooks.Open(sTargetPath & sTargetFile) C = C + 1 '- 'Make changes in open workbook here - Recalculation may be required '- oWB.Close SaveChanges:= True DoEvents sTargetFile = Dir 'Get next filename Loop MsgBox "Files opened: " & C, vbInformation ExitSub_: 'Reset macro optimization settings Application.ScreenUpdating = True Application.Calculation = xlOrigCalcMode Exit Sub ErrorHandler_ : 'Error if file is password protected, corrupted or missing, changes made to protected sheets etc MsgBox "Error in file: " & Err.Number & " " & Err.In putting together a client's file, Boneita needs to create a document that contains a list of everything in a particular folder-all documents and subfolders. Option Explicit Sub LoopAllExcelFilesInFolder () 'To loop through all Excel files in a user selected folder and perform a set task on them ' Const cFileFilter As String = "*.xl*" Dim oWB As Workbook Dim xlOrigCalcMode As XlCalculation Dim sTargetPath As String Dim sTargetFile As String Dim C As Long On Error GoTo ErrorHandler_ 'Optimize macro speed - 'Do not disable Application Events, as events won't fire when workbooks are opened Application.ScreenUpdating = False xlOrigCalcMode = Application.Calculation With Application.FileDialog(msoFileDialogFolderPicker). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |