VBA 8 Excel Objects PDF
VBA 8 Excel Objects PDF
ExcelFunctions.net
Search Site:
Custom Search
kup Tutorial
Each object in Excel has a number of Properties, which are
stored as a part of that object. For example, an Excel
Tutorial Worksheet's properties include the Worksheet's Name,
Protection, Visible Property, Scroll Area, etc. Therefore, if
ulas during the execution of a macro, we wanted to hide an Excel
worksheet, we could do this by accessing the Worksheet
ulas object, and altering the 'Visible' property.
https://www.excelfunctions.net/excel-objects.html 1/9
3/9/2020 Excel Objects
Application.
https://www.excelfunctions.net/excel-objects.html 2/9
3/9/2020 Excel Objects
(i.e. Sheets(1) or
Sheets("Sheet1")).
The above table shows how you can access Excel objects
via 'parent' objects. For example, a range of cells may be
referenced by the expression:
https://www.excelfunctions.net/excel-objects.html 4/9
3/9/2020 Excel Objects
Workbooks("WB1").Worksheets("WS1").Range("A1:B10")
Range("A1:B10")
Workbooks("Book1.xlsm").Activate
Worksheets("Data").Select
Range("A1", "B10").Select
https://www.excelfunctions.net/excel-objects.html 5/9
3/9/2020 Excel Objects
Object Properties
VBA objects have related Properties associated to them.
For example, the Workbook object has the properties
'Name', 'RevisionNumber', 'Sheets', and many more. These
properties can be accessed by referring to the object name
followed a dot and then the property name. For example,
the name of the current active Workbook can be accessed
by referring to ActiveWorkbook.Name. Therefore, to assign
the current active Workbook name to the variable wbName,
we could use the following code:
Workbooks("WB1").Worksheets("WS1")
Object Methods
VBA objects also have Methods that perform specific
actions. Object methods are procedures that are associated
to a specific object type. For example, the Workbook object
has the methods 'Activate', 'Close', 'Save', and many more.
ActiveWorkbook.Save
https://www.excelfunctions.net/excel-objects.html 6/9
3/9/2020 Excel Objects
ActiveWorkbook.SaveAs Filename:="Book2",
[FileFormat]:=xlCSV
Examples
Example 1
The following VBA code snippet was previously used to
illustrate the use of the For Each loop. It is now useful to re-
visit this code to examine the references to the Worksheets
object (taken from the current active Workbook by default),
and the reference to each individual Worksheet. Note that
the Worksheet 'Name' property is accessed, to display the
name of each Worksheet.
https://www.excelfunctions.net/excel-objects.html 7/9
3/9/2020 Excel Objects
Example 2
The following VBA code illustrates how you can access
Worksheets and Ranges in different Workbooks. It also
illustrates how the current Excel Objects are accessed by
default if no specific object is referenced. This example also
illustrates the use of the Set keyword to assign an Excel
object to a variable.
Sheets("Sheet1").Range("A1:B10").Copy
' Paste the values from the copied Range into the "Results"
Worksheet of
' the current Workbook. Note that, as CurrWb is not the current
Active
' Workbook, we need to specify this Workbook.
Workbooks("CurrWb").Sheets("Results").Range("A1").PasteSpecial
Paste:=xlPasteValues
Example 3
The following VBA code shows how the Columns
(collection) object can be accessed from the Worksheet
object. It is also seen that, when a cell or cell range on the
current active Worksheet is accessed, the reference to the
Worksheet can be omitted. Again the code provides an
example of the Set keyword, which is used to assign a
Range object to the variable 'Col'.
https://www.excelfunctions.net/excel-objects.html 8/9
3/9/2020 Excel Objects
Dim i As Integer
Dim Col As Range
Dim dVal As Double
Do Until IsEmpty(Col.Cells(i))
dVal = Col.Cells(i).Value * 3 - 1
https://www.excelfunctions.net/excel-objects.html 9/9