Return to VBA Code Examples

VBA – Programmatically Draw Boxes with Code

VBA Draw Boxes with Code

There are many reasons you may want to be able to programmatically draw boxes, an automated gantt chart would be cool? Here is one way to do it.

This is the basic code to draw a box:

It’s really not that daunting, there are only two notable things to look at; Schemecolor is obviously the color and the 0,0,48,12.75.

So what’s the 0,0,48,12.75? Simply the Left Position, Top Position, Width, and Height. You can adjust these however you would like, adjusting the first two to change the boxes position on the screen, and the latter two to change the size of the box. I used these dimensions becuase they were a good guess at making a box the same size as a cell.

Dynamic Boxes

And here is the code used to dynamically draw the green boxes in the above picture:

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!

<<Return to VBA Examples