Thursday, February 10, 2011

VBA有用小语句

经常忘记,每次都要上网再查一次,所以这次干脆总结一下,记录下来:

1)计算使用的行数:
Worksheets("Sheet1").UsedRange.Rows.Count
ActiveSheet.UsedRange.Rows.Count

2) 如有错误,忽略:
On Error Resume Next:

3) 弹出message box框:
Msgbox()
Msgbox ""

4) 给一个域解除锁属性:
Selection.Locked = False
给一个域添加锁属性
Selection.Locked = True

给一个域解除隐藏属性
Selection.FormulaHidden = False
给一个域添加隐藏属性
Selection.FormulaHidden = False

5)给一张sheet locked cells加锁:
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True

6)给sheet解锁
ActiveSheet.Unprotect Password:=""

http://blog.csdn.net/liujiaqiid/archive/2010/06/24/5692222.aspx

No comments:

Post a Comment