Hello, I am having some issues with a command I am trying to do. My goal is to have a worksheet saved in my folder C:\Users\1234\Desktop\Data .... with a macro button that does the following:
The purpose of step #1 is to leave a trail of the files within this folder the last time the macro was used.
I've found some code that I'm trying to modify, but cant seem to figure out how to fix these two glitches:
Any thoughts or suggestions?
- Copy/paste values of cells C2:E & "last row in column e" into column H2:K & "last row in column e"
- Looks at filepath in B2 of "File Extraction" worksheet
- Copy/pastes filenames and details of all files in this folder (file name, file path, file size, last modified date) in a table on the "File Extraction" worksheet beginning in C2
The purpose of step #1 is to leave a trail of the files within this folder the last time the macro was used.
I've found some code that I'm trying to modify, but cant seem to figure out how to fix these two glitches:
- Keeping that audit trail in step #1 (above)
- It only posts file name, but I also need file path, file size, last modified date
- It opens a window and makes me select the folder, instead of simply opening the folder I am trying to direct it to with "filename" variable in code
Any thoughts or suggestions?
Code:
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
Dim Filename As String
Filename = Format(Sheets("File Extraction").Range("A1") & ".xls")
InitialFoldr$ = "C:\"
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = Filename
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub