OLE Object -TexBox Properties

S

SSR

Hello ,

I have a Worksheet in which I'm Adding Text Box from the Control Toolbox via
VB Code. What I'm not able to do is to set the Properties of the Textbox in
the code.
I'm able to change the name as below
Set TextBoxCreated =
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", Link:=False,
DisplayAsIcon:=False, _
Left:=ActiveCell.Left, _
Top:=ActiveCell.Top, _
Width:=ActiveCell.Width, _
Height:=ActiveCell.Height)

TextBoxCreated.Name = ActiveCell.Address


But What I want to do is to change some more properties like
EnterKeybehavior and MultiLine which I'm unable to do. Can this be acheived
?
OR Can I Add the TextBox with the EnterkeyBehaviour and Multiline having
values as TRUE insted of the Default FALSE?

Thanks,
SSR
 
T

Tom Ogilvy

TestboxCreated is an OleObject. If you want to get to the textbox itself.
This code works for example:

Sub Tester1()
Dim TextBoxCreate As OLEObject
Dim tBox As MSForms.TextBox
Set textboxcreated = _
ActiveSheet.OLEObjects.Add(ClassType:="Forms.TextBox.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=ActiveCell.Left, _
Top:=ActiveCell.Top, _
Width:=ActiveCell.Width, _
Height:=ActiveCell.Height)

textboxcreated.Name = ActiveCell.Address
Set tBox = textboxcreated.Object
tBox.MultiLine = True
tBox.EnterKeyBehavior = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top