I'm Automating Inventor 2013 using UFT as follows:-
Set oApp = GetObject(,"Inventor.Application")
Set oDoc = oApp.ActiveDocument
Here I'm using GetObject()
function to get reference of running Inventor Application.
but I have a questions about GetObject()
function that
1)How it find out any application is present or in running state?
2)How it access header class of particular application so we will access of all methods and properties of that application's class?
can anybody explain this?
Excel VBA GETOBJECT Function. We can use GetObject function in VBA in MS Excel to access an ActiveX object from the excel file and then assign the object to an object variable.
GetObject([ pathname], [ class]) The GetObjectfunction syntax has these named arguments: Part Description pathname Optional; Variant(String). The full path and name of the file containing the object to retrieve. If pathnameis omitted, classis required. class Optional; Variant(String). A string representing the classof the object.
Use the GetObject function when there is a current instance of the object or if you want to create the object with a file already loaded. If there is no current instance, and you don't want the object started with a file loaded, use the CreateObject function.
If an object has registered itself as a single-instance object, only one instance of the object is created, no matter how many times CreateObject is executed. With a single-instance object, GetObject always returns the same instance when called with the zero-length string ("") syntax, and it causes an error if the pathname argument is omitted.
GetObject
and CreateObject
are part of COM automation provided by VBScript. VBScript can't use all the COM objects available through Windows. VBScript can use only those objects that expose a string called a programmatic identifier (ProgID
). Although not all COM objects have a ProgID, all COM objects have a 128-bit number called a class identifier, or CLSID. If a COM object has a ProgID, you can use VBScript to instantiate the object, invoke its methods and properties, and destroy the object.
GetObject
and CreateObject
works similar in a way, but they serve different purposes.
If you need to create a new instance of an object, use CreateObject.
If you need to reference an existing instance of an object, use GetObject.
GetObject
function has two optional arguments: the object's pathname
(i.e., a full path and a filename) and the object's ProgID
. Although both arguments are optional, you must specify at least one. If you omit both arguments, an error results. For example:
Dim wordDoc
Set wordDoc = GetObject ("FilePath\FileName.doc")
When this code is executed, the application associated with the specified pathname is started and the object in the specified file is activated. If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs.
If you specify the ProgID but not the pathname, the results differ depending on how you set up the arguments. If you pass an empty string as the first argument in code such as
Set wordApp = GetObject("", "Word.Application")
VBScript returns a new instance of Word's Application object (i.e., an object that represents the Word application). This GetObject call is equivalent to the CreateObject call
Set wordApp = CreateObject ("Word.Application")
If you omit the pathname argument but leave the comma
Set wordApp = GetObject (, "Word.Application")
VBScript returns an existing instance of the Application object if one exists.
For more information, check this and this links.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With