返回列表 上一主題 發帖

Excel VBA如何檢查_含有註解格數量

回復 7# Andy2483

3.再請教前輩 網查 Const 是常數的意思,有用它跟沒用都可以執行
3.1.在程式的設計上 Const 有甚麼時候是非用不可呢? 請您再指導
Const L = 20: Const T = 20

    Const 指定變數固定的內容 最好加註說明 ,當程式寫的龐大時如修改變數內容,只需修改這裡.
n7822123 , ikboy 的回覆多加練習,不懂可多看說明,再提問會進步的
下面的程式參考看看
  1. Option Explicit
  2. '365 之前版本只有 Comment 物件 為[註解]
  3. '365 版本中             Comment  物件 為[附註]
  4. '365 版本中 新增CommentThreaded 物件 為[註解]
  5. Sub Ex註解()
  6.     Dim Msg As String
  7.     With ActiveSheet
  8.         If .Comments.Count > 0 Then Msg = "[附註]   有" & .Comments.Count & "個 " & 註解副程式(.Comments)
  9.         If Application.Version >= 16 Then   '版本365以上
  10.              If Msg <> "" Then Msg = Msg & vbLf & vbLf
  11.             If .CommentsThreaded.Count >= 0 Then Msg = Msg & "[註解]   有" & .CommentsThreaded.Count & "個 " & 註解副程式(.CommentsThreaded)
  12.         End If
  13.         If Msg = "" Then Msg = .Name & " 沒有任何 註解...."
  14.         MsgBox Msg
  15. End With
  16. End Sub
  17. Function 註解副程式(comm As Object) As String
  18.     Dim e As Object, 註解 As String
  19.     For Each e In comm
  20.         If TypeName(e) = "CommentThreaded" Then   '版本365以上
  21.             註解 = 註解 & IIf(註解 <> "", vbLf, "") & e.Parent.Cells.Address & "  " & e.Text
  22.         Else ' 版本365以下
  23.             註解 = 註解 & IIf(註解 <> "", vbLf, "") & e.Shape.TopLeftCell.Address & "  " & e.Text
  24.         End If
  25.     Next
  26.     註解副程式 = vbLf & 註解
  27. End Function
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 對父母要知恩,感恩、報恩。
返回列表 上一主題