Question : Macro to insert a text box in spreadsheet

I would like a macro which inserts a text box within a spreadsheet at a specific size.

Answer : Macro to insert a text box in spreadsheet

Ok...I could not figure it out with that approach...it seems that when putting a text box on a sheet using code that way doesn't allow for certain properties.  I did figure out a work around though that may or may not be better for you.
First create a text box exactly like you want it, then set it's visible property to false.

Then use this code to copy it, paste it, and set the properties of the new text box..(Note:  if the text box you create already is the right size, then you can remove the 2 lines that set it's height and width)
With this approach, you can make the invisible text box look and act any way you want, then the code will just copy it, and place and size it where you need it.
I will also upload a file that is already working.  Just run the macro and it will create a text box in the upper left corner of the worksheet.

ps...
The line in the code that says this:
Selection.TopLeftCell.Select

is so that the text box won't be selected after it is created...remove that if you want..it selects the cell in the upper left corner of the text box


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Sub AddTextBox()
Application.ScreenUpdating = False
    ActiveSheet.Shapes("TextBox1").Visible = True
    ActiveSheet.Shapes("TextBox1").Copy
    ActiveSheet.Paste
        With Selection
            .Height = 25
            .Width = 200
            .Left = 20
            .Top = 20
        End With
    ActiveSheet.Shapes("TextBox1").Visible = False
    Selection.TopLeftCell.Select
    
Application.ScreenUpdating = True
 
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us