|
1、一个文件夹内有很多个excel表格,每一个表格中有一个工作簿名(sheet1),需要批量将整个文件夹中的excel表格的sheet1重命名为每个excel表格的A2内容。请问用vba如何操作?2、一个文件夹内有很多个excel表格,每一个表格中有一个工作簿名(汉字名),需要批量将整个文件夹中的excel表格的(汉字名)重名称为sheet1,如果有多个,则这个excel表格的第二个sheet2为。请问用vba如何操作?
3、请问两个vba执行,怎么合成一个执行?
本帖最后由 7171 于 2016-12-22 10:19 编辑
Sub t()
'把代码放到新的Excel文件中运行
strPath = ThisWorkbook.Path & Application.PathSeparator
strFilename = Dir(strPath & "*.xls*")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Do While Len(strFilename)
If strFilename <> ThisWorkbook.Name Then
With GetObject(strPath & strFilename)
.Windows(1).Visible = True
.Worksheets(1).Name = .Worksheets(1).Range("A2")
.SaveAs Filename:=strPath & .Worksheets(1).Range("A2")
.Close '
Kill strPath & strFilename
End With
End If
strFilename = Dir
Loop
End Sub
已修改,试试
|
|