Scriptorium

us fr nl




VBA: Controlling

Open a workbook at a specific worksheet
It is easy enough to open a workbook at a specific worksheet using a simple macro. However, what if you want do this from a shortcut or the command prompt? Afaik you can't run Excel at startup with a specific macro. There are numerous ways to solve this problem and this article descibes one of them. This method uses a batchfile to read a switch and write the read value (worksheet number) to a temporary textfile on disk. It then calls the Excel workbook which has a macro that is automatically started and read the the (worksheet)number stored in the textfile and opens the corresponding worksheet. Finally the running macro deletes the textfile.

Open files externally
This sub shows you an easy way to open a file (any file) in an external application.

Sending mouse clicks from VBA (using API call)
The SendKeys command allows one to send keystrokes from Office Applications to the foreground window. Unfortunately SendKeys can't send the PrintScreen key and it can't send mouse clicks. SendKeys is also a 'blind' command, it just sends keystrokes to whatever Windows (Windows applications only) is in the foreground. If the window you were targetting happened to be minimized the SendKeys command won't notice and send the keystrokes to a different window. If you need more control you'll have to resort to API calls that utilize the build in functionality of your Windows version. This article shows you how to do that.

Running DOS program from VBA - Get date and time of another computer on LAN
Following up on my earlier post "Running DOS programs from VBA" (http://scriptorium.serve-it.nl/view.php?sid=57) I thought I'd provide an example. There are quite a few good o'le DOS commands that are still useful. The biggest advantage of using DOS commands is that you often can get a lot of information with a single line command. In this example I'll show how to get the date and time of another computer (running Windows) on a local network. The DOS command to do that is simply NET TIME \\\\<computername> I've wrapped some code around this command to get the output in VBA.

Running DOS programs from VBA
Sometimes you want to execute a DOS program or command from VBA. This routine shows you how to do that. I demonstrate it by executing a PING command in a DOS box. Under the link section at the bottom you'll find a link to a sample workbook that demonstrates this.

Controlling other Applications - SendKeys example
This example shows the usage of the SendKeys command to control other Windows applications (Notepad, Calculator, Word etc.).

Copying data from Excel to Word
Copying data from Excel to Word is best done by creating a Word document object from Excel. That way Excel has a handle to the Word document object which makes it easier to control.

Atom Feed
Contact | About This Application | Scriptorium Website