My very first macro

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
ConradPlutt
Newbie
Posts: 1
Joined: Thu Sep 16, 2004 8:00 pm

My very first macro

Post by ConradPlutt » Thu Sep 16, 2004 8:07 pm

I got a Excel sheet with the Word "John" in a cell.
I want to put it in a variable and write it in the cell below.
(it could of course be done much easier, but I am doing
it this way for testing)
The cursor moves all right but I get nothing written. Could someone
please tell me what I am doing wrong?


SetFocus>Excel*
Press CTRL
Send Character/Text>c
Release CTRL
GetClipBoard>Name
Press Right
Press Down
Press Left
Wait>2
PutClipBoard>Name
Wait>2
Press CTRL
Send Character/Text>v
Release CTRL

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Sep 16, 2004 8:51 pm

I think the main problem may be Trailing Spaces, or it is possible that you have not selected anything to be copied? see note 4 below.

A number of things to watch for:

1. Remove any trailing spaces at the end of lines. This is especially important on Send, Goto, Label, all variables, like "name" in a few places.

2. Some programs are Case Sensitive with CTRL / ALT characters. Excel shows UPPERCASE C / V for Copy/Paste, you are using lowercase. Might not make a difference in Excel, but just a cautionary note.

3. Useful to refer to variable contents by using %percents% around the variables. Leave off the %percents% when you are referring to setting the value of the variable.

4. I know this is only a test macro, but I am a little confused. When you are using PutClipBoard, it does not seem that you are just putting back what is already there. I read your macro like this:
In an Excel spreadsheet, copy contents of current cell (are you on a cell?) to the clipboard(nothing is selected?)and call the contents "name", move down one cell, put "name" or the word "name" into the clipboard replacing what is already there, and paste the clipboard contents into the same cell.

Are you trying to copy contents from one cell to next lower cell? Try this (untested), assuming case is correct, and located in cell with contents to start:
SetFocus>Excel*
Press CTRL
Send Character/Text>C
Release CTRL
Press Right
Press Down
Press Left
Press CTRL
Send Character/Text>V
Release CTRL
If you want to use Clipboard, try something lilke this (untested):
SetFocus>Excel*
Press CTRL
Send Character/Text>C
Release CTRL
Press Right
Press Down
Press Left
GetClipBoard>Name
Send Character/Text>%Name%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mats

My very first macro

Post by Mats » Mon Sep 20, 2004 9:20 am

Thankyou Bob for your kind help!

What I really am up to is to read 8 cells of information in a row in Excel,
and put them into variables.
The cells hold mixed text and numbers with decimal comma.
Then switch to another application (ORACLE economical program) and insert them there. in 8 different fields. The insertion have to be performed through tab, enter is not valid.

I wanted to try out your code but get a error message
at the first line SetFocus>*Excel*

"Specified Window *Excel* Not Present.
Any Subsequent Key Sends In Script May Cause Exceptions"
It´s pussling

It is very strange as I have a window open and this line used to work

Regards
ConradPlutt

Guest

Post by Guest » Mon Sep 20, 2004 11:14 am

SetFocus>window_title

Sets focus to the specified window. The window_title may contain the * symbol at the end to indicate a wildcard.
Maybe that's the reason.
There's no option to get something like this wildcarded

Micosoft Excel - MyExcelWorkbookName.xls

Try to get the windows title and to set the focus to it, this way:
FindWindowWithText>text_to_find,1,WindowName

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Sep 20, 2004 4:09 pm

There's no option to get something like this wildcarded
MyExcelWorkbookName.xls
may not be totally correct.
SetFocus>Micosoft Excel - *
will work to get the Window for Excel. You may have to take additional steps to get to a specific workbook.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts