How do I insert Text Box in ActiveCell

B

Borg

I'm trying to create a macro to insert a Text Box (Autoshape) in an
Active Cell.

I used the VBA macro recorder to create an initial macro, but have no
been able to have the text box placed in the active cell. I trie
modifying the code, but each time it places the text box in the area
originally recorded the macro. I'm a beginner.

Here is an example of the vba code without modification:

ActiveSheet.Shapes.AddShape(msoShapeRectangle, 222#, 69.75, 72#, 72#)
_
Select
Selection.ShapeRange.ScaleWidth 6.26, msoFalse
msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.97, msoFalse
msoScaleFromTopLeft
Selection.Characters.Text = ""
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

Thanks in advance. :
 
D

Dave Peterson

I'd use something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myTextBox As TextBox

Set myCell = ActiveCell

With myCell
Set myTextBox = .Parent.TextBoxes.Add(Top:=.Top, Left:=.Left, _
Width:=.Width, Height:=.Height)
End With

With myTextBox
.Caption = "some stuff" 'if you want...
End With

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