在Excel用户表单中,如何更新标签的标题?

[英]In an Excel UserForm, how do I update a label's caption?


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?

我在Excel中创建了我的第一个无模态UserForm,并在其上添加了ActiveX标签。如何设置标签的标题,使其显示Sheet1.Range(“A1”)中的内容,并在单元格A1中的值发生变化时更新自身?

Basically, I want the Userform's label to always be updated the second anything in the Excel cell changes. Thank you!

基本上,我想让Userform的标签在Excel单元格的变化中总是被更新。谢谢你!

2 个解决方案

#1


4  

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

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).

每当单元格发生变化时,就调用subchange。代码是这样做的:如果A1被更改,则更改UserForm1上Label1的标题。表单必须是打开的,而不是模态(vbModeless)。

UserForm1.Show vbModeless

#2


1  

This Worked for me.

这为我工作。

Sheets("Sheet").Shapes("TheNameOfTheLabel").TextFrame.Characters.Text = "Hello"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/07/28/7118a43a9558de2f9ea4c342903e32eb.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号