Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Moving a shape with text inside without editing text

I am working on a project in Excel. I need to generate a shape, place text
inside that shape, and then allow the user to drag that shape around on the
sheet.

I have not been successful adding a shape, then using the TextFrame property
to add the text. Also have tried placing a text box.

If there is a way to "lock" the text so that it cannot be edited, maybe that
would work, but I can't find a way to do that.
Or, if there is a way to maybe add another shape on top of the text, and
group the text box to the shape, so that selecting the group and dragging has
the desired effect.

Can this be done? There must be a trick out there somewhere!

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Moving a shape with text inside without editing text

Yes There arr tricks. I went to the View Menu and adding the Drawing Toolbar
to my Excel workbook. I then recorded a new macro while I added a rectangle.
I then put a Textbox in the rectangle and added some text. The Macro3 below
is what was generated. To find the real name of the text again requires
tricks. I right clicked on the rectangle and selected Assign Macro where the
macro name was Rectangle2_Click. Now I knew the rectangle was called
Rectangle2. but you need to add a space to the name (see macro below). To
debug problems I add MyShape to watch window and then go into the wattch to
help find problems. that is how I found I needed to add a space in the
reference to "Ractangel 2"

Sub changetext()
For Each MyShape In Worksheets("sheet1").Shapes
Myshapename = MyShape.Name
Next MyShape

Set MyShape = Worksheets("sheet1").Shapes("rectangle 2")

End Sub



"Dan" wrote:


Sub Macro3()
'
' Macro3 Macro
' Macro recorded 3/10/2007 by jwarburg
'

'
Range("D15").Select
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 280.5, 167.25, 72#, 72#). _
Select
Selection.ShapeRange.ScaleWidth 2.28, msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 1.34, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Rectangle 2").Select
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
Selection.ShapeRange.ScaleWidth 0.86, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleWidth 1.28, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.18, msoFalse, msoScaleFromBottomRight
ActiveSheet.Shapes("Rectangle 2").Select
Selection.Characters.Text = "this is my message"
With Selection.Characters(Start:=1, Length:=18).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("D8").Select
End Sub


I am working on a project in Excel. I need to generate a shape, place text
inside that shape, and then allow the user to drag that shape around on the
sheet.

I have not been successful adding a shape, then using the TextFrame property
to add the text. Also have tried placing a text box.

If there is a way to "lock" the text so that it cannot be edited, maybe that
would work, but I can't find a way to do that.
Or, if there is a way to maybe add another shape on top of the text, and
group the text box to the shape, so that selecting the group and dragging has
the desired effect.

Can this be done? There must be a trick out there somewhere!

Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Moving a shape with text inside without editing text

Dim shp As Shape
Set shp = ActiveWorksheet.Shapes.AddShape(msoShapeRectangle,
CentimetersToPoints(1.5), CentimetersToPoints(1.5),
CentimetersToPoints(1.5), CentimetersToPoints(1.5), Selection.Range)
shp.Name = "MyName1"
shp.OnAction "ActionHandler"
ActiveWorksheet.Shapes.Range(Array("MyName0", "MyName1")).Group

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Moving a shape with text inside without editing text

Hi Dan,

In order to lock the text, the worksheet must be protected. The code
below will unprotect the sheet, add a shape to it, add the text, then
lock the text while still allowing you to move the shape around, and
finally re-protect the sheet.

Sub AddLockedTextShape()

Dim ws As Worksheet
Dim shp As Shape
Dim rng As Range
Dim w As Single
Dim h As Single

w = 48# ' standard cell width
h = 12.75 ' standard cell height

Set ws = ActiveSheet
Set rng = ws.Range("C3")

ws.Unprotect ' optional: use a password

Set shp = ws.Shapes.AddShape(msoShapeRectangle, rng.Left, rng.Top,
w, 4 * h)
shp.TextFrame.Characters.Text = "My Text"
shp.Select

' These don't have any affect unless the sheet is protected
With Application.Selection
.LockedText = True
.Locked = False
End With

ws.Protect

Set rng = Nothing
Set shp = Nothing
Set ws = Nothing

End Sub


HTH,

Nick Hebb
BreezeTree Software
http://www.breezetree.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
searching for text inside a text box wildetudor Excel Discussion (Misc queries) 0 January 21st 09 02:16 PM
How to embed large number of variables in text inside a text box? Riva Chase Excel Discussion (Misc queries) 0 October 30th 07 01:42 AM
Cutting and pasting large variable text into a text box shape usin AJL Excel Programming 0 October 30th 06 06:54 PM
How to make the text inside Text Box upside down? Kataro Excel Discussion (Misc queries) 1 December 21st 05 03:38 PM
Editing text in text box grouped within a trapezoid Linking to specific cells in pivot table Excel Programming 11 August 16th 05 09:17 AM


All times are GMT +1. The time now is 03:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"