Hi Kevin,

well, you're really asking many questions here, but I don't think you
realize all of them.

first, when you start a program by using the CreateObject() or GetObject()
method, it's not the same as if the started the program by choosing it from
a menu choice or a shortcut or clicking on it from windows explorer.

getting it running by use of CreateObject is called using COM automation, or
usually just automation; it specifically means one program under the control
of another.  it's a topic you should go do some research on, because it's
very important to your ability to write the more complex types of scripts.

In this case, the next question is whether a program will stay running, when
the program which opened it stops running.  you will need to look this
answer up in the object model documentation for each program you want to
use.

it turns out that Excel will not stay running, while MS Word will stay
running, so there's no predicting the answer.

Another question you'll see, is that with the hot key script you wrote, it
could have, and probably did, keep running, even though Excel shut down
right away.  this is because you opened excel from within a subroutine, and
assigned a variable to keep track of excel that was declared from within
this subroutine.  when this subroutine finished executing, which it did as
soon as excel opened up, it was done, it exited, and all the variables it
declared went away (called "going out of scope").

because they went away, it's equivalent to your script having stopped
running, at least as far as Excel goes, so excel shuts down.

excel, and many programs like it which shut down when the program that calls
them shuts down, has a property that you can set which will keep it from
shutting down when your program does.  the documentation for this prop-erty
is just below my answer.  if you just set this property to true before you
exit your subroutine, then excel will not shutdown.

the other way of handling this is to run excel the same way a shortcut would
have run it, or double clicking on it would have done.  this is simply
running it, and it will not be under your script's control, but it won't
close down on you either.

you don't do this via CreateObject, but via a method the operating system
provides for launching any program;  one way is to use CreateObject to
create the wscript.shell object, and then use the "run" method it has.  or,
the homer shared library has a shellrun method which will run a program for
you.

You asked about Wordpad, which is the last question I see, and why you
couldn't start it using createobject; it's because few program have a COM
object interface, like excel does, so when you go to try and use
wordpad.application, it's not there, and the operating system can't create
it for you.

the only way to start wordpad then is to use one of the program run methods
I mentioned above in that case.

you'll have to research each program you're interested in, to see if it has
a com object automation interface, to know whether you can control it via
createobject or not.

hth,

Chip

---------

UserControl Property
See Also
Applies To
Example
True
 if the application is visible or if it was created or started by the user.
False
 if you created or started the application programmatically by using the
CreateObject or
GetObject
 functions, and the application is hidden. Read/write
Boolean.
Remarks
When the
UserControl
 property is
False
 for an object, that object is released when the last programmatic reference
to the
object is released. If this property is
False
, Microsoft Excel quits when the last object in the session is released.  

-----Original Message-----
From: Kevin Simon Huber [mailto:kevin.hub...@gmail.com] 
Sent: Monday, August 03, 2009 12:27 PM
To: gw-scripting@gwmicro.com
Subject: loading an application from within a script

Hi:
I have written the following code based on an article from Sesame Script dim
testkey: set testkey =
keyboard.registerhotkey("shift-windows-t","turnonapp")
sub turnonapp
set ObjExcel = CreateObject("Excel.Application") ObjExcel.visible = true end
sub The problem is that when I press the hotkey, Excel appears and then
disappears whereas, if I just write a script containing:
set ObjExcel = CreateObject("Excel.Application") ObjExcel.visible = true
when I run the script, Excel will appear and stay until I manually close it.
Why is this happening?
I also discovered that when I replaced "excel with "wordpad" in the above
code, I get an error saying that the ActiveX component  couldn't create the
object.  What do I have to do if I want to open Wordpad or any other
application from within the script?
Kevin Huber
__________ Information from ESET Smart Security, version of virus signature
database


Reply via email to