new to excel macros


New Member
Apr 7, 2011
have programmed with C++,Java and am new to macros in excel

i have a project for which i have to write a design ( code already there )

since i am not used to VBA syntax i am not able to catch the head or tail of the application

my questions:

1) Thisworkbook - is this some sort of main

2) Modules - contains Functions , is there any structure when we write excel macros ?

or is it only Functions inside Modules

3) what are classmodules ?

4) when i start the macro , where does the program begin ?


Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.


Well-known Member
Aug 21, 2005
"thisworksbook" means the workbook in which the macro is parked.
functions are different from macros

macros are programmes to do something.

function is something like a formula. for e.g when you use sum(A!:A%) there is already an embedded function in excel

when you run a macro the programme starts at the first executable statement

sub test
dim r as range, j as integer, x as string
end sub

the programme starts with "worksheets("sheet1").activate" though it keeps the dim statements in the memory

You can get a good book excel macros.

Michael M

Well-known Member
Oct 27, 2005
Office Version
  1. 2013
  1. Windows
Hi kmm1977 and welcome to the Board.
There are heaps of places to help get your head around Excel VBA, mainly here of course.
But Hiker95 compiled this list of sites, videos, books,etc. to point users in the right direction. Some may be of assistance

Training / Books / Sites:

How to Learn to Write Macros

How to use the macro recorder

Click here and scroll down to Getting Started with VBA.

If you are serious about learning VBA try

Excel Tutorials and Tips - VBA - macros - training

See David McRitchie's site if you just started with VBA

Debra Dalgleish has some notes how to implement macros here:

David McRitchie has an intro to macros:

Ron de Bruin's intro to macros:

Creating custom functions

Writing Your First VBA Function in Excel

(livelessons video)
Excel VBA and Macros with MrExcel
ISBN: 0-7897-3938-0

Dependent validation lists. Debra has a neat little tutorial here.

Cascading queries

Excel Data Validation - Add New Items

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.

Locating files containing VBA
Searching Files in Subfolders for VBA code string:

Excel 2003 Power Programming with VBA, by John Walkenbach

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…

DonkeyOte: My Recommended Reading:




Pivot Intro

Email from XL - VBA

Outlook VBA

Function Dictionary

Function Translations

Dynamic Named Ranges

And, as your skills increase, try answering posts on sites like:

Where to paste code in VBE VBA
Introducing the Excel VBA Editor

VBA for Excel (Macros)

VBA Lesson 11: VBA Code General Tips and General Vocabulary

Excel VBA -- Adding Code to a Workbook

Explanation and Examples of VBA

Training for Excel, Access, VBA, with free downloads and course notes

VBA samples for Excel and outlook, couple of video tutorials

More VBA samples

Simple short VBA for beginners with explanations


Well-known Member
Jan 22, 2010
KMM the syntax is a little bizarre if you're used to C. I'm just now starting to get more in tune with VBA syntax and my background is some basic C so maybe I can help clear things up a little.

Functions are pretty much the same in C as they are in excel, with one exception.

In C, you'd name your function and as long as it wasn't a void function, you'd have something like return VariableName; at the end. but in vba, the function name itself is the variable that is returned. For example:

Long MyPCT(Long Retail, Long Wholesale)
long percentage = Retail / Wholesale -1;
return percentage;
Function MyPCT(Retail As Long, Wholesale As Long)
    MyPCT = Retail / Wholesale - 1
End Function
In C, your line could wrap as much as you want until your semicolon, but in excel, a new line is the end of the code so you'd have to manually extend your code with a _.

Excel also uses objects (which I'm not good at so someone else will have to fill in this gap), but I'd equate them to structs in C.

So far the two things in VBA that I don't like is the inability to comment out code blocks using /* and */ but rather you need to use the mouse. VBA also doesn't have an increment or decrement operator (++ and -- respectively).

Those are a few of the thigns I noticed, there's some trial and error but hope that helps at least a little.
Last edited:


New Member
Apr 7, 2011
thanx for the replies , i checked most of the sites you mentioned but did not find answer w.r.t to program structure

i do understand what a function can do etc.

but i did not understand

1) modules , are they similar to packages in java ?

2) what are class modules


Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics