简体   繁体   English

多行 Label 方框 VBA

[英]Multiline Label Box VBA

I have an issue with trying to make muliline entrys to a label box(inside a form), dont want to use a text box, I know there is a way to do it in code but I just can't seem to get it around my head all I try comes out false or returns only one value.我在尝试向 label 框(在表单内)中添加多行条目时遇到问题,不想使用文本框,我知道有一种方法可以在代码中执行此操作,但我似乎无法解决它我的脑袋我尝试的所有结果都是错误的或只返回一个值。 Basicly what I am traying to do is import a comlumn of text entrys, from colum B till the first empty cell, the text is already in the column.基本上我要做的是导入一列文本条目,从列 B 到第一个空单元格,文本已经在列中。 Now I need to get that text into multiple lines of a label field when I click the button.现在我需要在单击按钮时将该文本放入 label 字段的多行中。

Any help will be greatly appriciated.任何帮助将不胜感激。

Thank you!谢谢你!

Private Sub readbtn_Click()
Dim content As Variant
content = 1
Range("B1").Select
Do While Range("B" & content) <> ""
Me.ValuesLbl.Caption = Range("B" & content)
content = content + 1
Loop

Selection.End(xlDown).Select
End Sub

You can use the vbNewLine constant in the caption property of the Label control:您可以在 Label 控件的标题属性中使用 vbNewLine 常量:

Private Sub readbtn_Click()
   Dim content As Variant
   content = 1
   Range("B1").Select
   Me.ValuesLbl.Caption = "" 'clear any existing text in the Label control
   Do While Range("B" & content) <> ""
      Me.ValuesLbl.Caption = Me.ValuesLbl.Caption & Range("B" & content) _
                             & vbNewLine
      content = content + 1
   Loop
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM