2

Is there a way to add gridlines and snap objects to gridlines in an Excel VBA Userform?

I am generating a UserForm in Excel VBA with numerous textboxes and labels. Aligning them, even with the auto-align and grouping tools is quite tedious and time-consuming. The process would be expedited if horizontal and vertical gridlines were available to snap the objects to (think AutoCAD). The default UserForm has grid dots but not lines and snapping must be manually enabled for each object; it is not a built-in default for all objects.

Paul NoCal
  • 57
  • 1
  • 1
  • 7
  • Those features don't exist built-in, but maybe there is an add-in for it. I doubt it though. – Michael Z. Jul 03 '17 at 23:55
  • Not that I know of. The snapping behavior is a bit 50/50, depending on the control it will align to the dots or not when resizing. The top left point is aligned with the dots when dragging the control around. You could of course just add the controls at runtime from within the code and do the alignment and sizing there. – Rik Sportel Jul 04 '17 at 05:19
  • If you're generating the form in VBA, you can put the controls exactly where you want, so I don't really understand the question. – Rory Jul 04 '17 at 07:04
  • Hi Rory, that's true but grid-lines are just easier on my eyes; I would also rather not hard code the control positions. – Paul NoCal Jul 05 '17 at 07:02

2 Answers2

1

Turn on "Align Controls to Grid" in Tools => Options (dialog box) / General (tab) as shown below.

enter image description here

  • Thanks--I already knew how to do this though. It appears that there's way to add grid lines and I just have to settle for grid dots :( – Paul NoCal Jul 05 '17 at 07:03
1

You could add empty labels with the back color set to the border color you prefer. Shrink the lines to a height or width of 1 (depending on if it’s a horizontal or vertical line) and apply them over top of (and in line with) the grid dots.

starball
  • 20,030
  • 7
  • 43
  • 238