Hey! I've been struggling for the past 2 days now with finding a solution to a certain problem... This is the current code to create the shape:
So far so good, a shape is created based on the user-selection in the unlocked cells (can't select locked cells). This shape is editable by the user in both text-wise and location-wise. Observe that I am running several macros similar to this (except changing the name + shapestyle) so they need to be created separated from each other... My problem now:
I Don't want the user to be able to edit the shape (1 at a time) HEIGHT-wise, only in WIDTH. But the width must not exceed the specific boundaries that exists for the area of selection. Say I got 2 "Areas" the user can select between.
1 = A1:E8, 2 = G1:K8, where F-column = Locked.
Now I don't want the user to be able to resize the width of the shape no more then the boundary of "A1:E8" OR "G1:K8" depending on which area he started with his selection. I've sketched some of how I'd like the logics to work, but I am too unexperienced with VBA to make the code go live..
Anyone see a possible solution to this?
I found this what Jafaar wrote to be very interesting http://www.mrexcel.com/forum/excel-questions/607406-lock-my-shapes-user-resizing.html, but don't know how to do a
without selecting everything, I only want to select the objects within the cell-boundary?
Code:
Sub Test4()
Dim w As Integer
Dim h As Integer
Dim r As Range
Dim Shp As Shape
Set r = Selection
With Selection
h = Selection.Height
w = Selection.Width
End With
Sheet1.Unprotect
Set Shp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, r.Left, r.Top, w, h) 'Creates the shape and selects it
Shp.ShapeStyle = msoShapeStylePreset23
Shp.Locked = False 'Enables it to be moved and edited
Shp.ControlFormat.LockedText = False 'Enables editing of the text only within the box
Shp.Select
With Selection
.Characters.Text = "G1O"
.Characters.Font.Name = "Arial"
.Characters.Font.Size = 12
.Characters.Font.Bold = True
.HorizontalAlignment = xlHAlignCenter
.VerticalAlignment = xlVAlignCenter
End With
Application.CommandBars.FindControl(ID:=549).Execute 'snap to grid to objekt
Sheet1.Protect , _
UserInterFaceOnly:=True
Sheet1.ScrollArea = "$A$1:$HN$35"
End Sub
So far so good, a shape is created based on the user-selection in the unlocked cells (can't select locked cells). This shape is editable by the user in both text-wise and location-wise. Observe that I am running several macros similar to this (except changing the name + shapestyle) so they need to be created separated from each other... My problem now:
I Don't want the user to be able to edit the shape (1 at a time) HEIGHT-wise, only in WIDTH. But the width must not exceed the specific boundaries that exists for the area of selection. Say I got 2 "Areas" the user can select between.
1 = A1:E8, 2 = G1:K8, where F-column = Locked.
Now I don't want the user to be able to resize the width of the shape no more then the boundary of "A1:E8" OR "G1:K8" depending on which area he started with his selection. I've sketched some of how I'd like the logics to work, but I am too unexperienced with VBA to make the code go live..
Code:
If Selection Is within boundaries A1:E8 Set maximum size/Length of shape To A1:E8 / E8 (Or convert this Range To be a fixed number, since the Columns are fixed?) Shape.Height.Lock Or Shape.Height = Selection.Height As Fixed If Selection Is within boundaries G1:L8 Set maximum size of shape To G1:L8 Shape.Height.Lock Or Shape.Height = Selection.Height As Fixed etc etc
I found this what Jafaar wrote to be very interesting http://www.mrexcel.com/forum/excel-questions/607406-lock-my-shapes-user-resizing.html, but don't know how to do a
Code:
Set shpgrp = ActiveSheet.Shapes.Range(Array(shp1.Name, shp2.Name)).Group
without selecting everything, I only want to select the objects within the cell-boundary?
Last edited: