VBA/Macro code to get the value of textbox

早过忘川 提交于 2019-12-05 23:45:27

If TextBox1 is on a sheet named Main, then you can use this:

Worksheets("Main").TextBox1.Value

Better yet, you can give the sheet a CodeName of something like shtMain and then use

shtMain.TextBox1.Value

And finally, you can also get to the textbox through the shapes collection (but the methods above are preferable)...

Worksheets("Main").Shapes("TextBox1").OLEFormat.Object.Object.Value

You should be able to use foo = InputBox("bar").

If however you are getting it from a UserForm then it would be foo = UserForm1.TextBox1.Value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!