Search code examples
vbatextboxms-worduserform

How to add a borderless textbox to a UserForm at runtime


I would like to ask why .BorderStyle set to fmBorderStyleNone is not working when adding a new textbox during runtime? I want a textbox with no outline, but after the code runs there's still an outline.

 Dim txtB1 As TextBox
 Dim i

 For i = 0 To 5
     Set txtB1 = Frame12.Controls.Add("Forms.TextBox.1")
     With txtB1
         .Name = "chkDemo" & i
         .TextAlign = fmTextAlignCenter
         .Height = 20
         .Width = 36
         .Left = 444
         .Top = 10 * i * 2
         .BackStyle = fmBackStyleTransparent
         .BorderStyle = fmBorderStyleNone '---> this isn't working.
         .Font.Name = "Calibre"
         .Font.Size = 11
     End With
 Next i

Solution

  • The reason you still see an outline is because, by default, a text box is inserted with the special effect "sunken". You also need to change that property:

       .SpecialEffect = fmSpecialEffectFlat