Subrouines and graphics in VBA



I'm using VBA (Visual Basic 6.3) in Excel 2002.

Can I use VBA to write a program that is made up from a series of
subroutines, or the VBA equivalent? I remember using CALL in FORTRAN years
ago, but what is the corresponding VBA syntax?

Also, can VBA produce simple graphics (this could be a little difficult to
explain). For example as an output from a VBA program a simple diagram is
produced, such as lines, 2-D planes and cylinders. I'm not sure if VBA has
any graphics abilities.




Tim Williams

Sub Test1()
Msgbox "In Test1"
Msgbox "Back in Test1"
End Sub

Sub Test2()
Msgbox "In Test2"
End Sub

You can use shapes for simple graphics - see the drawing toolbar. Draw some shapes while recording a macro to get some idea of what
you code might look like.


VBA can pretty much issue all the command you can do manually. If you turn
on the macro recorder, then create your chart manually, then turn off the
macro recorder, it will give you a good start on the code you need to build a
chart. (delete the chart and run the code).

You call a subroutine by using call

Call macro2()

or just put in


Sub Main()
macro2 "hello Bob"
macro2 "How are you"
End sub

Sub Macro1()
msgbox "in macro1"
end sub

Sub Macro2(a as String)
msgbox "in macro2, " & a
End Sub
links to VBA tutorials follow links to general Excel tutorials




Make the drawing toolbar visible under View=>Toolbars

then look at the autoshapes and construct you diagram.

After you have it down, turn on the macro recorder and do it again to see
how the code works.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question