|
楼主 |
发表于 2021-6-18 10:57
|
显示全部楼层
谢谢老师的诚挚帮助!!!但我是32位系统,软件提示打不开。
老师能否帮我把下面一段代码修改一下,以完全达到我的要求。
1、指定文件夹改成对话框形式
2、对重复文件进行判断,增加序号,而不是采用Timer方式,虽然能对所有文件重命名,但文件名太长。
3,因为是恢复的文件,有的文件能重命名,但打不开,或是乱码,能不能用代码将这些文件命名时标记出来
网上搜的代码,我已经改动了一部分
'如何操作让工作薄和本工作薄中第一个工作表名称一致
Sub Renametest()
On Error Resume Next
Const PathName = "e:\ssx\Excel" '此处更改为实际文件夹路径
Dim WorkPath As Object
Dim Fso As Object
Dim xlFile As Object
Dim WB As Workbook
Dim ShName As String
Dim mycell As String
Dim ExtName As String
Set Fso = CreateObject("scripting.filesystemobject")
Set WorkPath = Fso.GetFolder(PathName)
For Each xlFile In WorkPath.Files
If UCase(Right(xlFile.Name, 3)) = "XLS" Or UCase(Right(xlFile.Name, 4)) = "XLSX" _
Or UCase(Right(xlFile.Name, 4)) = "XLSM" Then
Set WB = Workbooks.Open(PathName & "\" & xlFile.Name)
ShName = WB.Sheets(1).Name
mycell = WB.Sheets(1).Cells(4, 1).Value
ShName = ShName & mycell & Timer '工作簿名称为工作表1名称+工作表1单元格(4,1)名称+时间
WB.Close
If UCase(Right(xlFile.Name, 3)) = "XLS" Then
ExtName = ".xls"
ElseIf UCase(Right(xlFile.Name, 4)) = "XLSX" Then
ExtName = ".xlsx"
ElseIf UCase(Right(xlFile.Name, 4)) = "XLSM" Then
ExtName = ".xlsm"
End If
xlFile.Name = ShName & ExtName
End If
Next
End Sub
老师帮看一下,谢谢!!! |
|