Using VB graphics commands in VBA

mbrach

New Member
Joined
Jul 27, 2006
Messages
11
I am attempting to use the methods described in Rod Stephens "Visual Basic Graphics Programming" (2nd edition) in VBA with Excel. I'm hoping to be able to add a graphics window to a workbook that shows the relative position and orientation a couple of rectangles that represent two colliding vehicles. The position and orientation are based on data listed on Sheet1 of an Excel workbook.

I created a new module in the VB Editor and borrowed some simple code from the book that draws a rectangle using the Line command after changing the scale using the ScaleX and ScaleY commands. VBA did not like the scale commands but did not seem to mind the Line command.

The code I used:

'wid = ScaleX(5, vbPixels, ScaleMode)
'hgt = ScaleY(5, vbPixels, ScaleMode)
wid = 50
hgt = 50
Line (10, 10)-Step(wid, hgt), vbRed, BF

So I commented out the scale commands and filled numbers directly in the Line command. The code executes successfully (at least no errors) but I never get a window that opens up to display the rectangle.

I'm using Excel 2003 on a Vista machine.

Am I missing something in the availability of the VB commands in the VBA/Excel environment? Shouldn't I have all VB available to me?

Is this so simple that I'm really missing the boat on this? I am a novice at the graphics part of the VBA development, but have done a bit of programming in VBA.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi mbrach,

I'm not familiar with Rod Stephens' book, but since its title contains "Visual Basic" but not "VBA" I would guess that his book doesn't apply to VBA.

Nevertheless, you can do graphics in VBA, but I don't know of a way to open a separate window to do it in. You can create a separate sheet (a Chart sheet or worksheet), or even clear an area of the currently active worksheet to place and animate the graphics.

You will need to create the graphics using the Add method of the Shape object. I can send you an example or two if you are interested. If so, just PM me with your email address.

Damon
 
Upvote 0
The position and orientation are based on data listed on Sheet1 of an Excel workbook.

Post this data. You are trying to use methods that are available to VB, not VBA. Seeing that Excel has its own graphics model which is much more intuitive than VB's, use that. If you must use VB, then create your project in VB and compile it into a dll. You can then call it from VBA within Excel...
 
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,826
Members
449,411
Latest member
adunn_23

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