|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 dongjuwen 于 2019-9-30 12:40 编辑
创建类模块。类模块代码:
Public WithEvents Lbl As MSForms.Label
Private Sub Lbl_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
With Lbl
If X1 < 2 Or X1 > 50 Or Y1 < 2 Or Y1 > 15 Then
.Font.Size = 12
.ForeColor = &HFFFFFF
.BackColor = RGB(0, 176, 80)
Else
.Font.Size = 12.5
.ForeColor = RGB(255, 255, 0)
.BackColor = &H4763FF
End If
End With
End Sub
在ThisWorkbook_Open()
代码:
Private myLabel As New Collection
Private Sub Workbook_Open()
Dim objlabel As Object
Dim cmdlabel As New clsLabel
For Each objlabel In Sheet2.OLEObjects
If objlabel.OLEType = 2 Then
Set cmdlabel = New clsLabel
Set cmdlabel.Lbl = objlabel.Object
myLabel.Add cmdlabel
End If
Next
Set cmdlabel = Nothing
End Sub
捕捉X和Y坐标比较迟钝,有时间我再研究一下。这个代码马马虎虎(能用,但反应度不够) |
|