Sub AddTextbox()
Dim tbox As TextBox
' textbox will overlap, for example, range C3:H6
With Range("C3:H6")
Set tbox = ActiveSheet.TextBoxes.Add(.Left, .Top, .Width, .Height)
End With
tbox.Text = "This is an example"
End Sub
Sub Fancy_TextBox()
Dim tbox As Shape, MyText As String
MyText = " How do you make a textbox like this in Excel VBA" & vbLf & _
" " & Chr(149) & " So that it has indents" & vbLf & _
" " & Chr(149) & " and bullets like this" & vbLf & vbLf & _
" Any help would be greatly appreciated."
With Range("C3:H8")
Set tbox = ActiveSheet.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height)
End With
With tbox.DrawingObject
.Characters.Text = MyText
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
End With
Range("A1").Select
End Sub
Here's a little more...
Code:Sub Fancy_TextBox() Dim tbox As Shape, MyText As String MyText = " How do you make a textbox like this in Excel VBA" & vbLf & _ " " & Chr(149) & " So that it has indents" & vbLf & _ " " & Chr(149) & " and bullets like this" & vbLf & vbLf & _ " Any help would be greatly appreciated." With Range("C3:H8") Set tbox = ActiveSheet.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=.Left, Top:=.Top, _ Width:=.Width, Height:=.Height) End With With tbox.DrawingObject .Characters.Text = MyText With .Font .Name = "Arial" .FontStyle = "Regular" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With End With Range("A1").Select End Sub
Sub Fancy_TextBox()
Dim tbox As Shape, MyText As String
MyText = " How do you make a textbox like this in Excel VBA" & vbLf & _
" " & Chr(149) & " So that it has indents" & vbLf & _
" " & Chr(149) & " and bullets like this" & vbLf & vbLf & _
" Any help would be greatly appreciated."
With Range("C3:H8")
Set tbox = ActiveSheet.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height)
End With
With tbox.DrawingObject
.Characters.Text = MyText
With .Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
[COLOR="Red"] With .Characters(Start:=86, Length:=23).Font
[COLOR="Green"]' .Name = "Arial"
' .FontStyle = "Regular"
' .Size = 10
' .Strikethrough = False
' .Superscript = False
' .Subscript = False
' .OutlineFont = False
' .Shadow = False
' .Underline = xlUnderlineStyleNone[/COLOR]
.ColorIndex = [COLOR="Blue"]5[/COLOR]
End With[/COLOR]
End With
Range("A1").Select
End Sub