View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default View Code question

The code could be considered as a macro.

A macro can be run in a number of ways.

Sub Foo()
code to do something
End Sub

Can be run from a button or shortcut key and is generally stored in a standard
module.

Private Sub Worksheet_Change(ByVal Target As Range)
set the triggering event
make the change
code to do something or Call Foo which does its thing
End Sub

Is run automatically when a change is made.....thus it is called "event code"

All macros live in workbooks or add-ins(which are workbooks)

Browse through Chip's site for much more.


Gord Dibben MS Excel MVP

On Thu, 17 Jul 2008 09:27:00 -0700, Doug Waters 03/03/08
wrote:

So code in the View Code window IS a macro but just doesn't reside in a
module? And macros in worksheets and modules both reside in the workbook
file?

"Tim879" wrote:

typically you would put event procedures in the worksheet level and
"macros" in the modules.

the difference is the code placed in these sheets is usually for
worksheet level events (i.e. when a cell is changed, selected, etc.)
vs. code placed in modules which could be for anything.

For example, if you wanted to trigger a macro when a user entered a
value in a given cell, you would put the code to trigger the macro in
the worksheet.

this site has a great explanation of event procedures with some
examples.
http://www.cpearson.com/excel/Events.aspx




On Jul 17, 10:39 am, Doug Waters 03/03/08
wrote:
Please excuse an inexperienced but motivated newbie's question:

In Excel, when you right-click the tab for a given worksheet in a workbook,
and then select View Code from the resultant popup menu, what is the name of
the type of code that goes/resides in the Code window that then appears in
Visual Basic Editor (since it apparently is not a macro)? I need to know
what this type of code is called so I can research it when and how to use it.

Thanks for any help that anyone can provide.

Doug