Add Textbox created with Macro to any place in worksheet

tsheffer

New Member
Joined
Sep 16, 2013
Messages
16
Thanks in advance for taking a look at the issue we are having and helping with a solution!

We have recorded a Macro with a textbox (Insert Textbox - not a shape with text or Active X text box). We want to add this textbox wherever we want to on the sheet.
In other macros, once they were recorded, I deleted the selected range and this allowed us to place the macro wherever we wanted.

What do I have to change/add to allow us to place this macro wherever we want to?

Sub IntlShipment()
'
' IntlShipment Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
'
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 79.5, 25.5, 223.5, _
75.75).Select
Selection.ShapeRange.Height = 66.96
Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 8
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoFalse
Selection.ShapeRange.TextFrame2.TextRange.Font.Italic = msoTrue
Selection.ShapeRange.TextFrame2.TextRange.Font.UnderlineStyle = _
msoUnderlineSingleLine
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"International and Canada Shipments"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 34).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 34).Font
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
.Fill.ForeColor.TintAndShade = 0
.Fill.ForeColor.Brightness = 0
.Fill.Transparency = 0
.Fill.Solid
.Size = 8
.Italic = msoTrue
.Name = "+mn-lt"
.UnderlineStyle = msoUnderlineSingleLine
End With
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this:

This script will put the Textbox where ever your active cell is.

So click in the cell where you want the TextBox placed then Ctrl+Shift+I
And that is the place where your TextBox will be placed.


Code:
Sub IntlShipment()
'
' IntlShipment Macro
'
' Keyboard Shortcut: Ctrl+Shift+I
Dim Left As Double, Top As Double
With ActiveSheet
Left = ActiveCell.Left
Top = ActiveCell.Top
.Shapes.AddTextbox(msoTextOrientationHorizontal, Left, Top, 223.5, 75.75).Select
End With
Selection.ShapeRange.Height = 66.96
Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 8
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoTrue
Selection.ShapeRange.TextFrame2.TextRange.Font.Bold = msoFalse
Selection.ShapeRange.TextFrame2.TextRange.Font.Italic = msoTrue
Selection.ShapeRange.TextFrame2.TextRange.Font.UnderlineStyle = _
msoUnderlineSingleLine
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"International and Canada Shipments"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 34).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 34).Font
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
.Fill.ForeColor.TintAndShade = 0
.Fill.ForeColor.Brightness = 0
.Fill.Transparency = 0
.Fill.Solid
.Size = 8
.Italic = msoTrue
.Name = "+mn-lt"
.UnderlineStyle = msoUnderlineSingleLine
End With
End Sub
 
Upvote 0
Thank you, it now works! I had tried this earlier but I missed the End With before the Selection.ShapeRange lines.
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
Thank you, it now works! I had tried this earlier but I missed the End With before the Selection.ShapeRange lines.
 
Upvote 0
Ok, this worked when I tested it in my PERSONAL.XLSB worksheet but not in any other worksheet. I checked the macro and it is set for All Open Workbooks. I receive Run-time error 1004: The specified value is out of range.
When debug, this line is highlighted in yellow: .Shapes.AddTextbox(msoTextOrientationHorizontal, Left, Top, 223.5, 75.75).Select

***After further testing, this seems to work on any worksheet that I try, EXCEPT the one that I actually want it for. It is a macro-enabled worksheet, but I tried it on other macro-enabled worksheets and it works fine on them. It works fine on any standard Excel worksheet that I try it on also.
 
Last edited:
Upvote 0
The worksheet that I was trying to add it to was protected, even though the area I was trying to add it to allows for typing. If unprotect or allow for format changes it seems to work.
 
Upvote 0
Questions:
1.You said:
I checked the macro and it is set for All Open Workbooks.

Not sure what that means. If it's in your personal Workbook it will work on the active sheet in any open workbook

2. You said:
After further testing, this seems to work on any worksheet that I try, EXCEPT the one that I actually want it for.

If you only want it to work on just one worksheet then why put the script in your Personal Workbook?

You said:
It is a macro-enabled worksheet

Worksheets are not Macro Enabled.
Workbooks are Macro Enabled and all sheets in a Workbook are Macro Enabled.

This script is no different from the one you provide other than the location where the TextBox is located

Maybe you have two different scripts assigned the same shortcut key.
Or maybe you have a sheet event script running in the sheet where it will not work.

 
Upvote 0
Still unable to insert this box of text into two workbooks.
Will insert in any other blank sheet, worksheet, workbook, macro-enabled workbook.
The macro-enabled workbook that it doesn't work in sometimes has the macros removed, worksheets deleted and is re-saved as a .xlsx workbook. I am unable to insert the box in these workbooks also.
I verified that I don't have the two scripts with the same shortcut key. When using the macro shortcut key I receive a run-time error 1004 and the ".Shapes.AddTextbox(msoTextOrientationHorizontal, Left, Top, 223.5, 75.75) .Select" is highlghted.

Any ideas?
 
Upvote 0

Forum statistics

Threads
1,215,400
Messages
6,124,702
Members
449,180
Latest member
craigus51286

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