Using Get Object and Create Object in VBS

In VBA code, you can use GetObject to set a reference to an existing instance of an application, such as Word or Excel, to avoid creating numerous instances running in the background (you can see several WINWORD.EXE processes in the Task Manager in the following figure). Typically, an error handler detects whether GetObject set the reference, and if not, CreateObject is used instead. Although the GetObject function worked correctly in earlier versions of Windows, unfortunately, this technique doesn't work when you run VBS scripts in Windows Vista. Whether you use GetObject (with a slightly different syntax), or CreateObject, and whether or not there is a running instance of an application, a new instance is created every time the script is run.

fgj Windows Tiisk Manan« EH MJÍB!

File Options View Hel|j fgj Windows Tiisk Manan« EH MJÍB!

File Options View Hel|j

Image Name

User Name

CPU

Mem Usage

PRONoMgr.exe

Helen Feddema

00

3,240 K

sidebar.exe

Helen Feddema

00

11,736 K

SSstd8.exe

Helen Feddema

00

11,796 K

taskeng.exe

Helen Feddema

00

7,916 K

taskmgr.exe

Helen Feddema

04

7,220 K

winlogon.exe

00

3,356 K

WINWORD.EXE

Helen Feddema

00

41,428 K

WINWORD.EXE

Helen Feddema

00

23,920 K

WINWORD.EXE

Helen Feddema

00

41,120 K

WINWORD.EXE

Helen Feddema

00

41,680 K

WINWORD.EXE

Helen Feddema

00

23,916 K

WINWORD.EXE

Helen Feddema

00

42,348 K

WINWORD.EXE

Helen Feddema

00

23,920 K

WINWORD.EXE

Helen Feddema

00

24,588 K

wmdsync.exe

Helen Feddema

00

5,236 K

-

5how processes from all users

5how processes from all users

Multiple instances of Word in the Task Manager.

Viewing the numeric equivalents of named constants in the OlObjectClass Outlook enum in the Object Browser.

Object Browsei fe >

Classes dp OlMultiLine ip OlMultiSelect iP OINavigationModuleType OINetMeetingType OINoteOolor J> OIObieiKlaä IIIIIIII itp OlOfficeDocltemsType Itp OlOullookBarVlewType OIPageType OlPane >=P OlPermission ■IP OlPermissionService •sP OIRecipientSelectors

OIRecurrenceState up OIRecurrenceType OIReferenceType 01 Re mote Status OIResponseStatus (#" OIRuleActionType ■ip OIRuleConditionType j? OIRuleExecuteOption cOIRuleType OlSaveAsType OlScrollBars OlSearchScope

Members of'OlObjectClass'

S olConflicts bF

a olContactsModule iZi olDistributionList

CD olDocument iZi olException

CD olExceptions

CD o I Exchange Distribution List

CD olExchangeliser

Hi olExplorer

CD oIExplorers

LH olFolder

CD olFolders

CD olFormDescription

CD olFormNameRuleCondition

CD olFormRegion iD olFromRssFeedRuleCondition

CD olFromRuleCondition

CD olGroupByFields

CD ollmportanceRuleCondition a ollnspector

CD ollnspectors

S ol Item Properties

CD o I Item Property

® olltems

Const olContact = 4G (&H28) Member of Outlook .OlObjectClass

0 0

Post a comment