excel - 修改类 AllowEditRanges 中的范围

标签 excel vba

我已经在类 AllowEditRange 中手动设置了名为“Test”的项目。
我只需要通过 VBA 更改此项目的范围,但我不能。
我尝试了以下代码,但它什么也没做(没有引发错误)
谢谢大家可以帮忙。

Option Explicit
Option Compare Text

Private Sub Modify_User_EditRange()

    Dim ws As Worksheet
    Set ws = ThisWorkbook.ActiveSheet

    ws.Protection.AllowEditRanges("Test").Range = ws.Range("A2:A8")

End Sub
enter image description here

最佳答案

ws.Protection.AllowEditRanges("Test").Range返回 Range对象所以要修改它,你需要使用 Set陈述:Set ws.Protection.AllowEditRanges("Test").Range = ws.Range("A2:A8")

关于excel - 修改类 AllowEditRanges 中的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70121114/

相关文章:

Excel:在数据透视表中使用列分组的 count() 的 max()

excel - 如何在 XLA 文档中创建工具栏?

excel - 使用间接引用另一张工作表上的 Excel 命名范围

c - 如何构建一个类型以传递给一个 DLL 函数,该函数采用指向内部数组的结构的指针?

vba - 如何在 VBA excel 中将鼠标指针移到按钮上时显示更多信息。

vba - VBA格式时间问题

python - 合法 .xlsx 文件上的 openpyxl load_workbook() 会导致 zipfile.BadZipFile 错误

java - 在 java 中使用 Scanner 类以避免看到引号

Excel VBA 单元格字符限制

excel - "Run-time error ' 1004 ' Cannot edit a macro on a hidden workbook. Unhide the workbook using the Unhide command"在功能区 XML 中使用 "onLoad"时