Excel Object Model - Part1



Excel Object Model

Application, Workbook, Worksheet, Range



Ctrl+Y - deletes an entire line
Declaring Variables

Dim Age as Integer
Age= 77777 Integer - error 6 - overflow error
Dim decimals as a Double
Dim DOB as Date
Dim
false = 0 = No
True - not zero

Dim SuperRange as Range
Dim SuperWorksheet as Worksheet

variable names

s- string - Dim sFname as String
i- Integer
d- decimal
dt-Date
b - boolean
r - range
wk - worksheet
wb - workbook

Option Explicit - Declare your variables

Module based variable
Option Explicit

Private miAge as Integer

Private miAge as Integer ' Available across modules

Documentation

'Define variables
'Set Variables
' Change comments with green or highlight


Constant

const cFIRST  as Integer =0
You cannot define Dim sName as String = "Tim" - not allowed

Concatenation

Public Function FullName()
    ' Define Variables
    Dim sFirstName As String
    Dim sLastName As String
 
    'Set Variables
    sFirstName = "Ajith"
    sLastName = "Moni"
 
    'Combine variables
    FullName = sFirstName & sLastName
End Function


' Provide a # pound sign to signify the date to the parser #7/9/1965#

vbDefaultButton2

Public Sub Tester()
'Define Varibales
Dim sName As String

' Prompt the user for input data
sName = InputBox("Please enter your name", "Test", "First Name")

' Ask the user if the information is correct?
MsgBox "Are you sure this information is correct", vbQuestion + vbYesNoCancel + vbDefaultButton2, Verification

Src: http://techbus.safaribooksonline.com/video/office-and-productivity-applications/00022cworks

Analytics