Excel - VBA:Userform.Label 不会改变
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17288213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel - VBA : Userform.Label won't change
提问by Phalanx
My VBA program processes some operations on an input typed by the user and eventually gives back a result.
我的 VBA 程序对用户键入的输入进行一些操作,并最终返回结果。
At some point, I want to have some userform showing up and "adjusting" the research. For example, if the user typed a state and a city which doesn't fit, it would show "Did you mean cityin state? ". Then, clicking on yes would take into account the modification, clicking no wouldn't change anything.
在某些时候,我希望显示一些用户表单并“调整”研究。例如,如果用户输入了不适合的州和城市,它会显示“您的意思是州内的城市吗?”。然后,单击 yes 将考虑修改,单击 no 不会更改任何内容。
I have tried this, as found in some tutorials :
我已经尝试过这个,如在一些教程中发现的:
city = sMain.Range("J12").Value
province = sMain.Range("J6").Value
provinceSugg = sCurrent.Cells(p, db_column).Value
If province = "" And city <> "" Then
UserForm2.Show
UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
Else
End If
Unfortunately, it doesn't work at all, whatever text I write for Label1 and whatever way of writing I use (Label1.Caption = , Userform2.Label1.Caption = , Label1 = , etc.), still no change.
不幸的是,它根本不起作用,无论我为 Label1 编写什么文本以及我使用的任何书写方式(Label1.Caption = 、 Userform2.Label1.Caption = 、 Label1 = 等),仍然没有变化。
Thanks for helping me to fix this !
谢谢你帮我解决这个问题!
回答by sous2817
Set the caption before showing the form...like this:
在显示表单之前设置标题......像这样:
city = sMain.Range("J12").Value
province = sMain.Range("J6").Value
provinceSugg = sCurrent.Cells(p, db_column).Value
If province = "" And city <> "" Then
UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
UserForm2.Show
Else
End If
回答by matzone
Use vbModeless ..
使用 vbModeless ..
If province = "" And city <> "" Then
UserForm2.Show vbModeless
UserForm2.Label1 = "Do you mean : " & city & " in " & provinceSugg
Else
End If