VBA/Excel/Access/Word/Forms/TextBox

Материал из VB Эксперт
Перейти к: навигация, поиск

Add TextBox and format it

   <source lang="vb">

                          

Sub AddTextBox()

   ActiveSheet.Shapes.AddTextBox(msoTextOrientationHorizontal, 2.5, 1.5, _
       116, 145).TextFrame.Characters.text = "This is a test of inserting a text box to a sheet and adding some text."
   With Selection.Characters(Start:=1, Length:=216).font
       .name = "Arial"
       .FontStyle = "Regular"
       .size = 10
       .Strikethrough = False
       .Superscript = False
       .Subscript = False
       .OutlineFont = False
       .Shadow = False
       .Underline = xlUnderlineStyleNone
       .ColorIndex = xlAutomatic
   End With
   range("I15").Select

End Sub

</source>
   
  


Copy workbook differences to the worksheet

   <source lang="vb">

Private Sub cmdCopy_Click()

   Workbooks("Compare WorkBooks.xls").Worksheets("Sheet1").Activate
   Cells.Clear
   Range("A1").Select
   yourTextField.SelStart = 0
   yourTextField.SelLength = Len(txtReferences.Text)
   yourTextField.Copy
   ActiveSheet.Paste

End Sub

</source>
   
  


Read input from TextBox and assign the value to ActiveCell

   <source lang="vb">

Private Sub OKButton_Click()

   If CStr(SpinButton1.Value) = TextBox1.Text Then
       ActiveCell = SpinButton1.Value
       Unload Me
   Else
       MsgBox "Invalid entry.", vbCritical
       TextBox1.SetFocus
       TextBox1.SelStart = 0
       TextBox1.SelLength = Len(TextBox1.Text)
   End If

End Sub

</source>
   
  


Set the selection in a TextBox

   <source lang="vb">

Private Sub TextBox1_Enter()

   TextBox1.SelStart = 0
   TextBox1.SelLength = Len(TextBox1.Text)

End Sub

</source>