[英]VBA Excel: Replacing all sheets .CodeName value with .Name value
I want to change all sheets' .codename
value in VBA to their corresponding .name
values. 我想将VBA中所有工作表的
.codename
值更改为其相应的.name
值。 I am trying the below mentioned code but its not working. 我正在尝试下面提到的代码,但无法正常工作。 Kindly advise
好心提醒
Dim Ws As Variant
For k = 1 To 37
ThisWorkbook.VBProject.VBComponents(Ws(k)).CodeName = Ws(k).Name
Next k
Firstly you have to head onto Macro Security , on my version of Excel this can be found on the Developer tab. 首先,您必须转到Macro Security ,在我的Excel版本上,可以在“开发人员”选项卡上找到它。
Then tick the box that says " Trust access to the VBA project object model ". 然后勾选“ 信任对VBA项目对象模型的访问 ”框。
The following code should then allow you to achieve what you want: 然后,以下代码应允许您实现所需的目标:
Sub test()
For Each ws In ThisWorkbook.Sheets
ThisWorkbook.VBProject.VBComponents(ws.CodeName).Name = ws.Name
Next ws
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.