在Excel UserForm中,如何更新标签的标题? [英] In an Excel UserForm, how do I update a label's caption?
问题描述
我在Excel中创建了我的第一个无模 UserForm
,并在其上贴了ActiveX标签.如何设置标签的标题,以使其显示Sheet1.Range("A1")
中的内容,并在单元格A1中的值更改时自动更新?
I created my first modeless UserForm
in Excel and put an ActiveX label on it. How do I set the caption of the label so that it displays whatever is in Sheet1.Range("A1")
, and updates itself when the value in cell A1 changes?
基本上,我希望 Userform's
标签始终在Excel单元格更改之后的第二次更新.谢谢!
Basically, I want the Userform's
label to always be updated the second anything in the Excel cell changes. Thank you!
推荐答案
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Cells(1, 1), Target) Is Nothing Then
Exit Sub
End If
UserForm1.Label1.Caption = Sheet1.Range("A1").Value
End Sub
每次单元更改时,都会调用子Change
.该代码执行此操作:如果更改了A1
,请更改UserForm1
上的Label1
标题.表单必须已打开而不是模式(vbModeless
).
The sub Change
gets called everytime a cell changes. The code does this: if A1
was changed, change the caption of Label1
on UserForm1
. The form must have been opened not modal (vbModeless
).
UserForm1.Show vbModeless
这篇关于在Excel UserForm中,如何更新标签的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!