Dim rg As Range
If TypeName(Selection) = "Range" Then
'检测当前所选择的是否单元格对象
Debug.Print Selection.Address
'在立即窗口输出所选单元格的地址
For Each rg In Selection.Areas
'区域中循环(这样避免多选情况下有漏网之鱼)
With rg
.Columns.Font.Italic = True
'斜体
.Font.ColorIndex = 3
'字体颜色
End With
Debug.Print rg.Address
Next
End If
Worksheet.Comments 属性
返回一个 Comments 集合,该集合表示指定工作表的所有注释,只读。
示例:
Dim ct As Comment
If ActiveSheet.Comments.Count Then
For Each ct In ActiveSheet.Comments
Debug.Print ct.Text
'在立即窗口中显示批注内容
'可以用代码操作,添加批注
Next
End If
Worksheet.CustomProperties 属性
返回一个 CustomProperties 对象,该对象表示与工作表相关的标识符信息。
对于 CustomProperties 属性,工作表的标识符信息可以表示 XML 的元数据。
示例:
With ActiveSheet.CustomProperties
.Add Name:="hwc2ycy", Value:="VBA入门"
With .Item(1)
MsgBox .Name & vbTab & .Value
End With
End With
'向活动工作表添加标识符信息
用这招可以偷偷在工作表添加些不易被人发现的附加信息:-)