Copy and Paste Between Two Applications

 

Below is a simple example of how to set up a copy and paste routine between two applications. Use this as a guideline for creating routines between other 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 Window Activate command.

 

 

Setting up the Macro
 

a.From the Macro Express - Explorer menu click on Macro > New Macro to open a Create New Macro window.

b.The Activation defaults to HotKey.

c.Click on the HotKey edit box to place the cursor there.

d.Hold down the CTRL key, the SHIFT key and the P key all at the same time and release them.

e.CTRL+SHIFT+P is placed in the edit box and is the hot key assigned to activate the macro.

f.Enter Copy and Paste in the Nickname field and click OK to open the Script Editor.

g.Click on the Scope tab and make sure that the macro scope is set to global.

h.Click on the Script tab to start building the macro.

 

 

Building the Macro in the Script Editor

Step 1 - Give focus to Notepad
 

a.Expand the Windows/Programs category of commands and double click on the Window Activate command.

b.Enter "notepad" (without the quotes) as the Window title.

c.Make sure the Partial Match option is selected.

d.Click on the OK button to save the entry.

 

Step 2 - Highlight a line of text in Notepad

The object of the macro is to repetitively copy one line at a time over to WordPad. The first step in this process is to highlight a single line of text. This can be done by using Shift+End.

 

a.Expand the Keyboard category of commands and double click on the Text Type command.

b.Click on Shift and then End in the list of options in the yellow area of this window to insert <SHIFT><END> into the Keystrokes edit field.

c.Click OK to save the change.

 

Step 3 - Copy the highlighted text to the clipboard
 

a.Expand the Clipboard category of commands.

b.Double click on the Clipboard Copy command to insert into the script.

 

Step 4 - Adjust the text cursor in Notepad to be ready to copy the next line of text
 

a.Expand the Keyboard category of commands and double click on the Text Type command.

b.Click on Home and then Arrow Down in the list of options in the yellow area of this window to insert <HOME><ARROW DOWN> into the Keystrokes edit field.

c.Click OK to save the change.

 

Step 5 - Activate and give focus to WordPad
 

a.Expand the Windows/Programs category of commands and double click on the Window Activate command.

b.In the Activate Window field, enter "wordpad" (without the quotes) as the Window title.

c.Make sure the Partial Match option is selected.

d.Click on the OK button to save the entry.

 

Step 6 - Paste the text copied from Notepad into WordPad
 

a.Expand the Clipboard category of commands.

b.Double click on the Clipboard Paste command to insert into the script.

 

Step 7 - Position the cursor in Wordpad to accept the next paste 
 

a.Expand the Keyboard category of commands and double click on the Text Type command.

b.Click on Enter in the list of options in the yellow area of this dialog to insert <ENTER> into the Keystrokes edit field.

c.Click OK to save the change.

 

Step 8 - Place the macro in a repeat loop to copy multiple lines

In this example we will set the macro to copy the first 5 lines in notepad over to WordPad.

 

a.Highlight the first line of the macro script - Activate Window: "notepad".

b.Expand the Repeat category of commands and single click on the Repeat Start option

c.Click on the Insert Command Before Selected arrow - the top green arrow of the three insert arrows to open the Repeat Options window.

d.Make sure the Repeat Start option is selected and enter 5 in the Number of Times to Repeat entry field.

e.Click OK to save the change.

The Repeat command is inserted as the first line of the macro.

 

Step 9 - Close the repeat loop
 

a.Single click on the End Repeat command.

b.Click on the Add Command to End of Script button - the bottom of the three Insert buttons to insert the End Repeat command as the last command of the macro script.

 

Step 10 - Address possible timing issues with Wordpad

It's possible for Macro Express to send the Clipboard Paste command before WordPad has fully activated. This step will instruct the macro to wait until WordPad is ready to accept text input before continuing.

 

a.Expand the Timing category of commands and double click on the Wait for Window Title command.

b.Enter wordpad in the Window Title field.

c.Make sure the Partial Match option is selected.

d.Click OK to save the change.

e.Find where the Wait for Window Title was placed in the script and highlight it.

f.Click on the Up or Down Arrow located to the right of the script and move the command so that it is placed directly below the Window Activate: wordpad command.

 

Step 11 - Address possible timing issues with Notepad

Similar to the step above, we need to ensure that Notepad has focus and is ready to receive text input from the macro.
 

a.Highlight the Wait for Window Title command just inserted and click on the Duplicate button  to make a copy of this command. The Duplicate button is located to the right of the macro script.

b.There should now be two Wait for Window Title commands listed in the script.

c.Highlight one of the two commands and click on the Up or Down arrow on the right side of the macro script.

d.Move the command so that it is positioned directly below the Activate Window: "notepad" command.

e.Double click on the Wait for Window Title command that was just moved and change the Window Title from wordpad to notepad.

f.Click OK to save the change.

 

Step 12 - Save the macro
 

a.Click on File > Save to save the macro.

 

 

Macro Script

The macro script should look like what is displayed below. If the macro does not look like this, arrange the commands so that they are in the following order, using the up and down arrows to the right of the script.

 

 

Repeat Start (Repeat 5 times)

  Window Activate: notepad

  Wait for Window Title: notepad

  Text Type (Simulate Keystrokes): <SHIFT><END>

  Clipboard Copy

  Text Type (Simulate Keystrokes): <HOME><ARROW DOWN>

  Window Activate: wordpad

  Wait for Window Title: wordpad

  Clipboard Paste

  Text Type (Simulate Keystrokes): <ENTER>

End Repeat

 

 

Testing the Macro

 

a.To test the macro run the notepad and WordPad applications. 

b.Enter five lines of text into notepad or copy the first five lines of the macro script displayed above and paste them into notepad.

c.Make sure that there are no blank lines between the lines of text.

d.Next, place the mouse cursor at the beginning of the first line of text in notepad.

e.Then press CTRL + Shift + P to start the macro and watch it switch between both programs, copying each line from notepad and pasting into WordPad.