Creating specific editable shapes via Macro in protected sheet, VBA

CorZor

New Member
Joined
Jul 29, 2013
Messages
6
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:

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
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
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:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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