|
楼主 |
发表于 2021-6-18 09:52
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
谢谢老师的帮助,但我电脑使用的是32系统,软件打不开。老师能否提供一下源码,不甚感激!!!
或者帮忙把下面一段代码给改良一下。这段代码是我从网上搜的,做了一些改变,中间部分能达到要求。
老师能否把 1 ,Const PathName = "e:\ssx\Excel"红字部分改成对话框方式(像打开我和文档一样),2 ,增加重复文件判断,Timer 改成序号形式。
谢谢!!!
'如何操作让工作薄和本工作薄中第一个工作表名称一致
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
Dim n As Long
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
|
|