|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
谢谢老师,但代码中有几个小问题,变量前后不一致。
Sub test()
Dim arr(), brr()
Dim r%, i%
Dim mypath$, myname$
mypath = ThisWorkbook.Path & "\"
myname = Dir(mypath & "*.*", vbDirectory)
m = 0
Do While myname <> ""
If myname <> "." And myname <> ".." Then
If GetAttr(mypath & myname) = vbDirectory Then
m = m + 1
ReDim Preserve arr(1 To m)
arr(m) = myname
End If
End If
myname = Dir()
Loop
For k = 1 To UBound(arr)
mypath = ThisWorkbook.Path & "\" & arr(k) & "\"
myname = Dir(mypath & "*.docx")
m = 0
Do While myname <> ""
m = m + 1
ReDim Preserve brr(1 To m)
brr(m) = myname
myname = Dir()
Loop
For i = 1 To UBound(brr)
Name mypath & brr(i) As mypath & arr(k) & "-" & Format(i, "000") & "." & Split(brr(i), ".")(1)
Next
Next
End Sub |
|