[英]Excel VBA: Dynamic range for ComboBox.Rowsource values not displayed when userForm called from commandbutton
[英]Excel VBA Set a Commandbutton Caption from a Userform Textbox
我在excel電子表格上有一個按鈕(不在用戶窗體中),並且我有一個userfrom上有一個文本框,並且希望這樣做,當我在用戶窗體的文本框中輸入名稱以設置標題時我在excel工作表上的按鈕的位置,直到在文本框中輸入的值。 我想知道我需要使用什么代碼以及在哪里插入該代碼?
希望有道理,請記住,我是新手,所以這就是為什么我要在哪里插入代碼
提前謝謝了
假設一個名為TextBox1的文本框,您的用戶窗體中的代碼可能如下所示:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(Me.Textbox1.text) > 0 then
ActiveSheet.Buttons("Button 1").Caption = Me.Textbox1.text
End If
End Sub
或者,如果您希望標題在鍵入時更新:
Private Sub TextBox1_Change()
If Len(Me.TextBox1.Text) > 0 Then _
ActiveSheet.Buttons("Button 1").Caption = Me.TextBox1.Text
End Sub
當您使用“ CommandButton”(這是一個ActiveX控件),但似乎正在朝Form控件前進時,我已經使用了您需要的2種方法:
ActiveX:
ActiveSheet.Shapes("YourButton").OLEFormat.Object.Object.Caption = "YourText"
形式:
ActiveSheet.Shapes("YourButton").TextFrame.Characters.Text = "YourText"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.