vba 解锁由单元格名称 Office 2007 选择的 Excel 中的单元格范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3628642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unlocking range of cells in excel selected by cellname Office 2007
提问by echox
I have 3 cells which are merged with each other and are referenced to with a given cellname (for example "foo").
我有 3 个单元格,它们彼此合并并使用给定的单元格名称(例如“foo”)进行引用。
I now want to unlock these cells with the locked
attribute.
我现在想用locked
属性解锁这些单元格。
The lock in the following code will notwork, but the value will be successfully assigned to the cell:
以下代码中的锁不会起作用,但会成功将值分配给单元格:
Workbooks(loadedSheetName).Worksheets("foo").Range("bar").Locked = False
Workbooks(loadedSheetName).Worksheets("foo").Range("bar") = "foo value"
What will work is referencing the cells by "coordinates" but is not really an option for me:
有效的是通过“坐标”引用单元格,但对我来说并不是一个真正的选择:
Workbooks(loadedSheetName).Worksheets("foo").Range("B3:E3").Locked = False
Is there any possibility to select some merged cells by name and set the locked
attribute to false?
有没有可能按名称选择一些合并的单元格并将locked
属性设置为false?
回答by Dr. belisarius
The following code works OK in my Excel 2007
以下代码在我的 Excel 2007 中运行正常
Sub aa()
Dim ce As Range
Application.ScreenUpdating = False ''# screen flicker off
ActiveSheet.Unprotect Password:=""
For Each ce In Range("rng")
ce.MergeArea.Locked = "False"
Next ce
ActiveSheet.Protect Password:=""
End Sub
HTH!
哼!
回答by Fandango68
You don't need to go through every cell in a Range
.
您不需要遍历Range
.
Simply...
简单地...
Range("myRangeName").Select
Selection.Locked = False