Copy and Paste Between Two Applications


Below is a simple example of how to set up a copy and paste routine between two applications. You can use this as a guideline for creating routines between your specific applications.

 

You might be tempted to try and use the ALT+TAB key to switch between programs. This is actually not always reliable and in fact, will not even work via Macro Express on some computers due to the low level nature of this key command. The solution is to use the ACTIVATE command.

 

Setting up the Macro

From the Macro Express Explorer menu click on Macros | Add Macro. A new window should appear titled Add Macro. Hot Key should already be selected and the blinking cursor should be in the edit box. If the cursor is not in the edit box, click on the edit box with the mouse to place it there. Next, hold down the CTRL key, the SHIFT key and the P key all at the same time and then release them. CTRL+SHIFT+P should appear in the edit box. This is the hot key we will define for the macro.

 

Next click on the Scripting Editor button start building the macro in the Scripting Editor. First click on the Properties Tab and enter Copy and Paste in the Nickname field. Next click on the Scope tab and make sure that the macro scope is set to global. Then click on the Script tab to start building the macro.

 

Building the Macro in the Scripting Editor

1) Scroll through the list of command categories and click on Windows/Programs to expand the list. Double click on the Window Activate command. In the Activate Window field, enter "notepad" (without the quotes) as the Window title. Click on the OK button to save the entry. This first command instructs the macro to bring notepad to the front and be ready to receive keystrokes.

 

2) We now want to enter our commands to be processed in notepad. Let's assume we want to repetitively copy one line at a time over to Wordpad. Our next command would be to highlight a single line of text. This can be done by using Shift+End. To do this scroll through the list of command categories and click on Text to expand the category. Then double click on Text Type to open the Text Type window. Click on Shift and then End in the list of options in the yellow area of this window. This should insert <SHIFT><END> into the Keystrokes edit field. Click OK to save your changes.

 

3) The next step is to copy this to the Windows Clipboard. Scroll through the list of command categories and click on Clipboard to expand the category. Double click on the Clipboard Copy command to insert this to your script.

 

4) Now that the line has been copied to the clipboard, we are ready to go paste it into Wordpad. But first, lets move the cursor to the next line in notepad so we will be ready to copy the next line. To do this, scroll through the list of command categories and click on Text to expand the category. Then double click on Text Type to open the Text Type window. Click on Home and then Arrow Down in the list of options in the yellow area of this window. This should insert <HOME><ARROW DOWN> into the Keystrokes edit field. Click OK to save your changes.

 

5) Now to activate Wordpad, we follow the same process as before by scrolling through the list of command categories and clicking on Windows/Programs to expand the list. Double click on the Window Activate command. In the Activate Window field, enter "wordpad" (without the quotes) as the Window title. Click on the OK button to save the entry. This command will activate Wordpad and allow text entry into this window.

 

6) The next step of the macro is to paste the text from the clipboard into Wordpad. To do this scroll through the list of command categories and click on Clipboard to expand the category. Double click on the Clipboard Paste command to insert this to your script.

 

7) Now let's place an <ENTER> into the macro which will move the cursor to a new line in Wordpad. To do this, scroll through the list of command categories and click on Text to expand the category. Then double click on Text Type to open the Text Type window. Click on Enter in the list of options in the yellow area of this window. This should insert <ENTER> into the Keystrokes edit field. Click OK to save your changes.

 

8) We are almost done now. There are two final issues that we need to address. First we need to place the macro in a loop so that it copies multiple lines. Let's set the macro up so that it copies the first 5 lines in notepad over to Wordpad. Highlight the first line of your macro script - Activate Window: "notepad". Then scroll through the list of command categories and click on Repeat to expand the category. Single click on the Repeat Start option and then click on the Insert Before arrow - the top blue arrow of the three insert arrows. This will open the Repeat Options window. Make sure the Start Repeat option is selected and enter 5 in the Repeat Count entry field. Click OK to save the change. This should insert the Repeat command as the first line of your macro.

 

9) Single click on the Repeat End command and then click on the Add to End insert button - the bottom of the three Insert buttons. This should insert a Repeat End command as the last command of your macro script.

 

10) The last thing we need to do is address a possible timing issue. It's possible for Macro Express to send the Clipboard Paste command before Wordpad has fully activated. So what we need to do is insert a short delay right after activating either window. To do this, scroll through the list of command categories and click on Timing to expand the list. Then double click on Delay to open the Set Delay window. Select the Delay in Seconds option and enter .5 (a half second). Click OK to save the change.

 

Find the delay command in the script and highlight it. Then click on the Duplicate button to make a copy of this command. The Duplicate button is the bottom of the three buttons to the right of the Macro Script. You should now have two Delay commands listed in the script. Highlight one of the Delay commands and click on the Up or Down arrow on the right side of the Macro Script. Move the delay command so that it is positioned below the Activate Window: "notepad" command and above the Text Type:<SHIFT><END> command. Go back and highlight the other Delay command and move it so that it is positioned below  Activate Window: "wordpad" command and above the Clipboard Paste command.

 

Macro Script

Your macro script should look like what is displayed below. If your macro doesn't look like this, arrange the commands so that they are in this order.

 

Repeat Start (Repeat 5 times)

Activate Window: "notepad"

Delay 0.5 Seconds

Text Type: <SHIFT><END>

Clipboard Copy

Text Type: <HOME><ARROW DOWN>

Activate Window: "wordpad"

Delay 0.5 Seconds

Clipboard Paste

Text Type: <ENTER>

Repeat End

 

Testing the Macro

Click on File | Save to save the macro. Next run the notepad and Wordpad applications. (To run notepad, click on Start | Run from the bottom left of the computer screen, enter notepad and click the OK button. To run Wordpad, click on Start | Run from the bottom left of the computer screen, enter wordpad and click the OK button.)

 

Enter five lines of text into notepad or copy the first five lines of the macro script displayed above and paste them into notepad. Make sure you don't have any blank lines between the lines of text. Next, place the mouse cursor at the beginning of the first line of text in notepad. Then press CTRL + Shift + P to start the macro. It should switch between both programs copying each line from notepad and pasting them into Wordpad.