The Power Loon
New Member
- Joined
- Feb 7, 2020
- Messages
- 34
- Office Version
- 365
- Platform
- Windows
The attached macro renames files in a given folder.
When starting, I get a prompt to select the folder in question. I am looking to remove this step, and instead use the pathway specified in cell H1. However, I have been unsuccessful in my attempts to do so.
How do I remove the pathway selection step in the macro below and instead use the pathway listed in cell H1?
Thank you for your consideration of this question
When starting, I get a prompt to select the folder in question. I am looking to remove this step, and instead use the pathway specified in cell H1. However, I have been unsuccessful in my attempts to do so.
How do I remove the pathway selection step in the macro below and instead use the pathway listed in cell H1?
VBA Code:
Sub RenameFiles()
Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
xDir = .SelectedItems(1)
xFile = Dir(xDir & Application.PathSeparator & "*")
Do Until xFile = ""
xRow = 0
On Error Resume Next
xRow = Application.Match(xFile, Range("A:A"), 0)
If xRow > 0 Then
Name xDir & Application.PathSeparator & xFile As _
xDir & Application.PathSeparator & Cells(xRow, "B").Value
End If
xFile = Dir
Loop
End If
End With
End Sub
Thank you for your consideration of this question