Tip Okay, so what if you would like Excel to be visible on screen? This little script will create an instance of Microsoft Excel and—just like magic—make that instance appear on your screen: As an introduction to Microsoft Office scripting lesson number 2, let's modify this script so it creates an instance of Excel, displays it on screen, pauses for 10 seconds, and then quits.
Consider, for example, the need to create a bunch of new user accounts in Microsoft® Active Directory®.
Could you do that by passing command-line parameters to a script? But think about how easy it would be for your HR department (or whoever) to type all this information in Excel; in fact, there's a good chance that's what they already do.
The point is, you can run a script by starting it from the command prompt and passing it a bunch of command-line arguments; in addition, you can output data to the command window or to a text file. The truth is, there are lots of times you don't need anything else.
On the other hand, sometimes—just sometimes, mind you—system administrators look at applications like Microsoft® Excel and think about how nice it would be to harness some of the capabilities Excel for their own use.
You should see an instance of ) In other words, here is your first official Microsoft Office scripting lesson: By default, any time you use a script to create an instance of a Microsoft Office application, that application runs in a window that is not visible on screen. (Sort of like the last raise they said you got.) Now, believe it or not, this is actually a good thing. As you'll soon see, you can programmatically read data from it or, for that matter, do pretty much anything else you can do with Excel.
The only functionality you lose when Excel runs in an invisible window is the ability to type something on the keyboard and have the application react to those keystrokes. Suppose you were running a script that created a report using Excel, and suppose Excel was visible the whole time the script was running.
A user (even yourself) could accidentally hit a key on the keyboard and ruin the entire report.
A user (even yourself) could simply close Excel, ruining not only the report, but also causing your script to blow up.
When the script process terminates, the File System Object terminates as well. When the script runs, you'll notice that only one new process is created (either or Wscript.exe, depending on which script host you are using).
That's because both the script and the File System Object share that process.
Okay, stop fretting; we'll write a File System Object script for you: Now, write a script that creates an instance of Microsoft Excel, open up Task Manager, and then run that script.