I have written a (basic) macro that I use to create a Control Button attached and sized to the currently selected Cell.
I would like for the Button to always have the same size as the Cell.
I have tried using “ResizeToCell = TRUE” on the Shape object that contains the Button, but that’s not doing it.
Here’s is the code I’m using:
' Create and configure a Command Button with Type=URL
oButton = oDoc.createInstance("com.sun.star.form.component.CommandButton")
oButton.ButtonType = com.sun.star.form.FormButtonType.URL
oButton.Name = sButtonLabel + "_Button"
oButton.Label = sButtonLabel
oButton.TargetURL = sURL
oButton.FocusOnClick = false
oButton.Repeat = false
obutton.BackgroundColor = RGB(255, 255, 215) ' ***** WHY DOES THIS CHANGE (DARKEN) AFTER I CLICK ON IT??? *****
obutton.TextColor = RGB(0, 150, 200)
' Create and configure a FontDescriptor for the Button and apply it
oFontDesc = oButton.FontDescriptor
' oFontDesc = oDoc.createInstance("com.sun.star.awt.FontDescriptor")
oFontDesc.Name = "Arial"
oFontDesc.Height = 12
oFontDesc.Weight = 175 ' This is a PERCENTAGE
oButton.FontDescriptor = oFontDesc
oShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
oShape.Name = oButtonLabel + "_Shape"
oShape.Control = oButton ' Set the Button as the Control in the Shape
oSheet.DrawPage.add(oShape) ' Add the Shape (that contains the Button) to the Sheet
oShape.Size = oSelection.Size ' Size the Shape with the Size of the selected Cell
oShape.Position = oSelection.Position ' Position the Shape into the selected Cell
oShape.Anchor = oSelection ' Anchor the Shape to the selected Cell
oShape.ResizeWithCell = true ' Resize the Shape every time the Cell size changes???
oShape.SizeProtect = true ' Don't allow the user to resize the Shape
oShape.MoveProtect = true ' Don't allow the user to move the Shape