gpt4 book ai didi

Excel 宏什么都不做?

转载 作者:行者123 更新时间:2023-12-04 21:13:19 24 4
gpt4 key购买 nike

这是我的第一个 excel 宏(也是第一次使用 VBScript),所以它很可能是错误的,但我正在尝试浏览我的工作簿中的每个工作表,并将工作表重命名为工作表“A2”单元格的值值(value)。顾名思义,当我运行该函数时,它什么也没做。但是它正在运行。这是我的代码:

Sub RenameSheets()

Dim WS_Count As Integer
Dim I As Integer

' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.
For I = 1 To WS_Count

ActiveSheet.Name = ActiveSheet.Range("A2").Value

Next I

End Sub

最佳答案

Sub RenameSheets()

Dim WS_Count As Integer
Dim I As Integer

WS_Count = ActiveWorkbook.Worksheets.Count

For I = 1 To WS_Count
Dim WS As Worksheet
Set WS = ActiveWorkbook.Worksheets(I)

'Worksheet names can not be null
If Len(WS.Cells(2, 1)) > 0 Then

WS.Name = WS.Cells(2, 1)

End If

Next I

End Sub

关于Excel 宏什么都不做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6793699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com