搜索
写经验 领红包
 > 游戏

如何批量修改工作表的名称(批量更改工作表名称)

导语:【实例06-批量修改工作表名称】Excel表格VBA编程实例 代码分享

Dim wbname As String

Private Sub CommandButton获取_Click()

&34;名称列表&39;清除原列表数据

.Columns(1).ClearFormats

.Columns(1).ClearContents

.Columns(2).ClearFormats

.Columns(2).ClearContents

End With

With ThisWorkbook.Worksheets(&34;)

If .Cells(2, &34;).Value <> &34; Then

wbname = .Cells(2, &34;).Value

Else

MsgBox &34;

Exit Sub

End If

End With

Dim i As Integer

For i = 1 To Workbooks(wbname).Worksheets.Count

ThisWorkbook.Worksheets(&34;).Cells(i, 1).Value = Workbooks(wbname).Worksheets(i).Name

Next i

ThisWorkbook.Worksheets(&34;).Activate

End Sub

Private Sub CommandButton修改_Click()

With ThisWorkbook.Worksheets(&34;)

If .Cells(2, &34;).Value <> &34; Then

wbname = .Cells(2, &34;).Value

Else

MsgBox &34;

Exit Sub

End If

End With

With ThisWorkbook.Worksheets(&34;)

Dim i As Long

Dim imax As Long

imax = .Cells(1000000, 1).End(xlUp).Row

For i = 1 To imax

If .Cells(i, 1).Value <> &34; And .Cells(i, 2).Value <> &34; Then

Workbooks(wbname).Worksheets(CStr(.Cells(i, 1).Value)).Name = CStr(.Cells(i, 2).Value)

End If

Next i

Workbooks(wbname).Save

MsgBox &34;

End With

End Sub

本文内容由小媛整理编辑!