And VBA statement execution automatically after each file name _ and figures out, my idea is to search all the files in the folder, according to the key words such as "personal RiBiao" in a name changed to "personal RiBiao. XLSX", "department RiBiao" in a name changed to "department RiBiao. XLSX", "product sales RiBiao" in a name changed to "product sales RiBiao. XLSX"
The small white is, however, the statement patchwork go to change a little, write their own not to come out, for which the teacher free help,
C: \ Users \ \ Administrator \ Desktop \ RiBiao export raw
Personal RiBiao _20020201017893251. XLSX
Department RiBiao _20020201017345236. XLSX
Product sales RiBiao _200202010176982. XLSX
CodePudding user response:
select folder after removing _ + digital file cannot with nameSub demo ()
Dim path As a String, the name As a String, arr (),, reg index As Long As the Object
With the Application. The FileDialog (msoFileDialogFolderPicker)
. The Title="select rename folder"
. InitialFileName=Application. DefaultFilePath
The Show
If. SelectedItems. Count & gt; 0 Then
Path=. SelectedItems (1) & amp; ""
The Else
The Exit Sub
End the If
End With
Name=Dir (path & amp; "*. *" xl, vbDirectory)
The Do While Len (name) & gt; 0
ReDim Preserve arr (0 To index)
Arr (index)=name
The index=index + 1
Name=Dir
Loop
Dim As Long I
The Set reg=CreateObject (" vbscript. Regexp ")
With reg
. The Pattern="_ (\ d) +"
On the Error Resume Next
For I=0 To index - 1
If the test (arr (I)) Then
The Name path & amp; Arr (I) the As path & amp; The Replace (arr (I), "")
End the If
Next I
On Error GoTo 0
End With
End Sub