Trying to add a textbox with VBA, but getting a Smiley Face instead

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,200
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Excel 2007, Vista.
When I step through the code and hover over "Type:= msoTextBox" the tip pointer indicates a value of 17 which is consistent with the mso shape type enum for a TextBox, but Excel produces a smiley face instead. Am I missing something?
Code:
Sub TBoxAdd()
Dim sh As Shape
'next line returns a smiley face
Set sh = ActiveSheet.Shapes.AddShape(Type:=msoTextBox, Left:=100, Top:=100, Width:=100, Height:=100)
MsgBox sh.Name  'Returns "Smiley Face #"
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
i saw this from andy pope
You get the smiley face when adding a shape because the constants share
the same value.

msoShapeSmileyFace = 17
msoTextBox = 17

Use AddTextbox instead

Code:
[COLOR=#273D49][FONT=arial]..AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=100, _[/FONT][/COLOR]
[COLOR=#273D49][FONT=arial]Top:=100, Width:=100, Height:=100)[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top