I need to change how some code looks up a certain directory, previously I had it static where it was just a set folder. However now I want to make it a cell reference on a workbook im just not sure how to do so. Below is what I have, I would like it so its refering to cell A2 on a tab called Renaming, code to change in red below
This is the line of code I need to change which works fine.
Set objFolder = objFSO.GetFolder("D:\Users\d12\Desktop\John\Data Files - Test")
This is the entire piece of code
Sub Listfilenames()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("D:\Users\d12\Desktop\John\Data Files - Test")
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path
'Cells(i + 1, 2) = objFile.Path
i = i + 1
Next objFile
End Sub
This is the line of code I need to change which works fine.
Set objFolder = objFSO.GetFolder("D:\Users\d12\Desktop\John\Data Files - Test")
This is the entire piece of code
Sub Listfilenames()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("D:\Users\d12\Desktop\John\Data Files - Test")
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path
'Cells(i + 1, 2) = objFile.Path
i = i + 1
Next objFile
End Sub