new to excel macros

kmm1977

New Member
Joined
Apr 7, 2011
Messages
2
Hi
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 ?

regards
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
"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

e.g.
sub test
dim r as range, j as integer, x as string
worksheets("sheet1").activate
...
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.
 
Upvote 0
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
http://articles.excelyogi.com/playin...ba/2008/10/27/

How to use the macro recorder
http://articles.excelyogi.com/

Click here and scroll down to Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Creating custom functions
http://office.microsoft.com/en-us/ex...117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Y...Excel/631.html

http://www.excel-vba.com/
http://www.mvps.org/dmcritchie/excel/getstarted.htm
http://www.exceltip.com/excel_links.html

(livelessons video)
Excel VBA and Macros with MrExcel
ISBN: 0-7897-3938-0
http://www.amazon.com/Excel-Macros-M...7936479&sr=1-1

http://www.xl-central.com/index.html

http://www.datapigtechnologies.com/ExcelMain.htm

Dependent validation lists. Debra has a neat little tutorial here.
http://www.contextures.com/xlDataVal02.html

Cascading queries
http://www.tushar-mehta.com/excel/ne...ing_dropdowns/

http://www.contextures.com/xlDataVal05.html


Excel Data Validation - Add New Items
http://www.contextures.com/excel-dat...ation-add.html

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.
http://www.cpearson.com/Excel/vbe.aspx

Locating files containing VBA
Searching Files in Subfolders for VBA code string:
http://www.dailydoseofexcel.com/arch...a-code-string/

http://www.pcreview.co.uk/forums/thread-978054.php

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…
http://www.mrexcel.com/learnexcel2.shtml

DonkeyOte: My Recommended Reading:

Volatility
http://www.decisionmodels.com/calcsecretsi.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Arrays
http://www.xtremevbtalk.com/showthread.php?t=296012

Pivot Intro
http://peltiertech.com/Excel/Pivots/pivotstart.htm

Email from XL - VBA
http://www.rondebruin.nl/sendmail.htm

Outlook VBA
http://www.outlookcode.com/article.aspx?ID=40

Function Dictionary
http://www.xlfdic.com/

Function Translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

And, as your skills increase, try answering posts on sites like:
http://www.mrexcel.com/
http://www.excelforum.com/
http://www.ozgrid.com/
http://www.vbaexpress.com/portal.php
http://p2p.wrox.com/excel-vba-79/


Where to paste code in VBE VBA
Introducing the Excel VBA Editor
http://www.ask.com/web?qsrc=2417&o=1...cel+VBA+Editor

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Explanation and Examples of VBA
http://www.beyondtechnology.com/vba.shtml

Training for Excel, Access, VBA, with free downloads and course notes
http://www.fontstuff.com/excel/index.htm

VBA samples for Excel and outlook, couple of video tutorials

http://www.codeforexcelandoutlook.com

More VBA samples
http://msmvps.com/blogs/nateoliver

Simple short VBA for beginners with explanations
http://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm#J
 
Upvote 0
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:

Code:
Long MyPCT(Long Retail, Long Wholesale)
{
long percentage = Retail / Wholesale -1;
return percentage;
}
Code:
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:
Upvote 0
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

regards
kmm
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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