export folder list

Vishal302019

New Member
Joined
Sep 2, 2020
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Public rowIndex As Long

Sub MainProc()

Dim DirName As String

Application.DisplayAlerts = False
Application.ScreenUpdating = False
rowIndex = 2
DirName = Sheets("Macro").Range("B4").Value
Sheets("Macro").Range("H2:M200000").Clear
Sheets("Macro").Range("H1:M200000").Columns.AutoFit

If DirName = "" Then
MsgBox "Please provide valid Folder Name", vbCritical, "Error"
End
End If

If Dir(DirName, vbDirectory) = "" Then
MsgBox "Please provide valid Folder Name", vbCritical, "Error"
End
End If

Call ListFilesInFolder(DirName, True)

Sheets("Macro").Range("H1:M" & rowIndex).Select
Selection.Borders.LineStyle = xlContinuous
Selection.Borders.Weight = xlThin
Selection.Columns.AutoFit
Range("H2").Select

End Sub
Sub ListFilesInFolder(ByVal xFolderName As String, ByVal xIsSubfolders As Boolean)
Dim xFileSystemObject As Object
Dim xFolder As Object
Dim xSubFolder As Object
Dim xFile As Object

Set xFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFileSystemObject.GetFolder(xFolderName)

For Each xFile In xFolder.Files
Sheets("Macro").Cells(rowIndex, 8).Value = rowIndex - 1
Sheets("Macro").Cells(rowIndex, 9).Value = xFolder
Sheets("Macro").Cells(rowIndex, 10).Value = xFile.Name
Sheets("Macro").Cells(rowIndex, 11).Value = "File"
Sheets("Macro").Cells(rowIndex, 12).Value = xFile.DateCreated
Sheets("Macro").Cells(rowIndex, 13).Value = xFile.DateLastModified

rowIndex = rowIndex + 1
Next xFile

If xIsSubfolders Then
For Each xSubFolder In xFolder.SUBFOLDERS
Sheets("Macro").Cells(rowIndex, 8).Value = rowIndex - 1
Sheets("Macro").Cells(rowIndex, 9).Value = xFolder
Sheets("Macro").Cells(rowIndex, 10).Value = xSubFolder.Name
Sheets("Macro").Cells(rowIndex, 11).Value = "Subfolder"
Sheets("Macro").Cells(rowIndex, 12).Value = xSubFolder.DateCreated
Sheets("Macro").Cells(rowIndex, 13).Value = xSubFolder.DateLastModified

rowIndex = rowIndex + 1
ListFilesInFolder xSubFolder.Path, True
Next xSubFolder
End If
Set xFile = Nothing
Set xFolder = Nothing
Set xFileSystemObject = Nothing


End Sub


Private Sub cmdclearsheet_Click()
Sheets("Macro").Range("B4").Value = ""
Sheets("Macro").Range("H2:M200000").Clear
Sheets("Macro").Range("H1:M200000").Columns.AutoFit
Range("B4").Select
End Sub

Private Sub cmdgetinfo_Click()
Call MainProc
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You are trying to use rowindex in a called procedure where it has not been initialized. You can either make it a public variable or pull it over from the original procedure by adding it as a parameter variable. Or declare it anew and initialize it within the called procedure.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,046
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top