Share this Page URL

A VBA Language Primer > Objects - Pg. 421

functions and subprocedures. (The prefix " g " is often used to indicate a global var- iable.) Variables and routines declared as Private can be used only within the code module in which they reside. In Word VBA, since modules are attached to templates, there is another consideration: which project (template) the module belongs to. To call a procedure in another project, you must set a reference to that project in the calling project. This is done using the References dialog accessible from the Tools menu in the VBA window. Example 18-22. Using Public and Private Keywords Public gintLookAtMe As Integer Private strShyVar As String Dim dtmVar As Date Public Sub DoThis( ) Private Sub SecretFunc( ) ' visible outside this code module ' visible in this module only ' visible in this module only ' callable from other code modules ' callable only from this module You'll notice that Public and Private can be used in place of Dim to explicitly define a variable's module scope. Declaring a variable with the Dim keyword is the same as declaring it Private . Objects In VBA programming, objects are logical abstractions that represent components of the host application (in this case, Word). Objects have properties (attributes) and