[OTP] VBA: Projects, objects and modules.

I started learning VBA in MS Word today. I have some programming experience in C++ and Java. I am trying to understand how the environment is structured and what Projects, Objects and Modules represent.

For example I recorded a few macros using the macro recorder and then opened the VB Editor to see what was created. I notice that under "Project" (which represents the entire document I assume) are 3 folders. One is named "Microsoft Word Objects". Within this folder is what looks like a file named "This Document". What does "This Document" represent? What is the difference between "This Document" and the "Project"?

Also under "Project" is a folder named "Modules". Within this folder is what looks like a file named "New Macros". This "file" seems to hold the code that represents the macros I recorded. Right clicking on the "Modules" folder allows me to insert another module into which I can add code for a Sub/s (short for subroutine/s I assume) via the VB Editor to do whatever.

Why would you put code for different Subs into different modules? The simple tutorials I have been studying seem to put all Subs into the one module. Why is the code for the recorded macros put into a separate module?

I am trying to work out exactly what Projects, Objects, and Modules are and how they interact. It seems like some sort of hierarchy. This environment is very new and quite confusing to me at the moment. Any help or references appreciated.

[1492 byte] By [une] at [2007-12-28]
# 1

Hi,

A project or solution is an overall method or means in which to get a task done and

a project/solution folder contains all the files associated with that program or solution.

Objects are any item like a button, a textbox etcetera that may be used in a project or

can be for example a spaceShip in object orientated programming.

A module is a piece of code that can not be inherited.

A CLASS can be inherited and as an example a CLASS called "anAccount"

may have accountName, sortCode, accountNumber as member properties.

Properties are things like the characteristics of an object like colour, size etcetera.

Subs yes are subroutines.

Macros can be all in one module or not.

The Macro code as separate modules allows some flexibility where you may

not want to load or install every Macro, particularly where memory available may be low.

Inheritance is about an object or class inheriting or getting the properties and methods of another,

this is coded at CLASS level usually.

Hope this clears a few thing up for you?

Regards,

S_DS

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Unfortuntately, you are posting your question in the wrong forum - this is for Visual Basic and not Visual Basic for Applications: although some concepts are similar, there are significant differences that could cause confusion. You may be able to get support for VBA here:

http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=74&SiteID=1

or:

http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.word.newusers&lang=en&cr=US

HTH

[OTP]

SJWhiteley at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Thanks. I initially looked for a VBA forum at MSDN but could not find one. Thanks for the link.
une at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...