0

I have a well working VBA script that when a target cell with the value, "Click to Learn More" is clicked, a corresponding informational pop-up shape is made visible.

My hope is that I'll be able to add code that realigns the shape's right edge to the target cell's left edge, preferrably centered vertically as with the screenshot example. I've tried some suggestions using msoAlignRight, but I'm not enough of a VBA expert yet to know the right syntax -if that's even the right way of doing this.

enter image description here

Thanks for any suggestions!

(The name of the corresponding shape is assigned to the variable, "ImgName", and the "Click for More Information" cell is the Target cell.)

Teamothy
  • 2,000
  • 3
  • 16
  • 26
QFarley
  • 91
  • 8
  • Please post the code you've tried and any error messages etc. – SJR Oct 10 '18 at 16:44
  • There's no one version of added code -I've tried a bunch of different things. I know that makes helping me here much more open-ended, but that's the nature of my request -general or specific guidance on the VBA code structure on how I could do this. – QFarley Oct 10 '18 at 16:57
  • That's not really how the site works so your question might be closed. Basically I think you have to set the left property of the shape as the left property of the cell minus the width of the shape. – SJR Oct 10 '18 at 17:03

2 Answers2

0

Have you tried ShapeRange's Align method for that. Like you said, you want to align right edge of your source shape to left edge of target shape. As described in https://learn.microsoft.com/en-us/office/vba/api/word.shaperange.align, this can be done using this method.

  • Thank you for responding. Yes, it was that MS webpage where I got the idea to try msoAlignRight, but I just couldn't get the syntax right in translating their brief example to my script. – QFarley Oct 10 '18 at 16:38
0

Here is an illustration:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim s As Shape

Set s = ActiveSheet.Shapes("Rectangle 1")

If Target.Address = "$G$10" Then
    With s
        .Visible = True
        .Left = Target.Left - s.Width - 10
        .Top = Target.Top + (Target.Height - s.Height) / 2
    End With
Else
    s.Visible = False
End If

End Sub

enter image description here

SJR
  • 22,986
  • 6
  • 18
  • 26