I have a table of indeterminate number of rows. I need to establish focus on a certain cell in the table and then progress down row by row making a change. I need to copy information from one cell in a row so that it can be used to determine the change in the next cell in that same row. So far I've used mouse coordinates to designate the first cell to be in focus, but when I run the Repeat/Until function, naturally it returns to the original mouse coordinates that picked the first cell to begin with.
How can I initiate the focus on a cell WITHOUT mouse coordinates so that when it runs the Repeat/Until loop, it doesn't return to the originally focused cell, instead allowing the procedure to run from the point the Tab stops in my programming have taken it to?
Once again, thanks in advance...
Ronen Ben-Hai
Zutphen, Netherlands
Finding focus in a specific table cell
Moderators: Dorian (MJT support), JRL
Determine strategy first.
Hi GalaxyMan,
First you need a strategy on how you are going to access and manipulate the table.
Could you send a copy of the code you have so far? It may help to know just what kind of table you are automating. There may be easier ways to do this for certain types of tables. For example if it is an Excel spreadsheet you don't need to use any mouse clicks or key presses at all.
If this table is part of an application take notes on how you navigate to the various cells manually. You say you would like to avoid mouseclicks. Can you navigate to any cell using the keyboard? How do you manually navigate to the desired column? If the table displays 20 rows at at time, how do you get to row 21? How does the application tell you you reached the last cell.
The following code example assumes you need to you the mouse. If you have the Macro Scheduler editor and the table open at the same time you can point the mouse to the any point on the table and the x,y coordinates will display in the editor. Use those numbers in your script.
//set initial coordinates xx,yy to just above first cell
//Use the editor to find the initial coordinates.
//Find the coordinates of row1 and row2 to determine cellheight.
//maxcount is the number of rows in the table.
//For the first version of your script, get variable values manually.
//k, xx, yy, cellheight, and maxcount are all variables you define.
This next example assumes you need to use the mouse to find the first cell and can use key presses for all subsequent rows.
Your final script will need to be more complicated than this to account for how the table behaves after you reach the last visible row. You may also be able to press the Down arrow instead of moving the mouse to move focus to the next cell. All depends on how hour application behaves.
If this is an Excel table or a database you may be able to access the table directly using VBScript or DBQuery.
Gale
First you need a strategy on how you are going to access and manipulate the table.
Could you send a copy of the code you have so far? It may help to know just what kind of table you are automating. There may be easier ways to do this for certain types of tables. For example if it is an Excel spreadsheet you don't need to use any mouse clicks or key presses at all.
If this table is part of an application take notes on how you navigate to the various cells manually. You say you would like to avoid mouseclicks. Can you navigate to any cell using the keyboard? How do you manually navigate to the desired column? If the table displays 20 rows at at time, how do you get to row 21? How does the application tell you you reached the last cell.
The following code example assumes you need to you the mouse. If you have the Macro Scheduler editor and the table open at the same time you can point the mouse to the any point on the table and the x,y coordinates will display in the editor. Use those numbers in your script.
//set initial coordinates xx,yy to just above first cell
//Use the editor to find the initial coordinates.
//Find the coordinates of row1 and row2 to determine cellheight.
//maxcount is the number of rows in the table.
//For the first version of your script, get variable values manually.
//k, xx, yy, cellheight, and maxcount are all variables you define.
Code: Select all
Let>k=0
Let>maxcount=25
Repeat>k
Let>k=k+1
Let>yy=yy+cellheight
MouseMove>xx,yy
LClick
Until>k=maxcount
Code: Select all
//Click on coordinates of first row in column.
MouseMove>xx,yy
LClick
Let>k=0
Let>maxcount=25
Repeat>k
Let>k=k+1
//Process current cell
//Move focus to next cell
Press Down
Until>k=maxcount
Your final script will need to be more complicated than this to account for how the table behaves after you reach the last visible row. You may also be able to press the Down arrow instead of moving the mouse to move focus to the next cell. All depends on how hour application behaves.
If this is an Excel table or a database you may be able to access the table directly using VBScript or DBQuery.
Gale
Last edited by gdyvig on Mon Jun 29, 2009 4:43 pm, edited 2 times in total.
More detail added to previous post.
Hi,
I added some more stuff to my previous post.
Gale
I added some more stuff to my previous post.
Gale
Hi, Gabe.
Thanks for the expanded explanation.
What I'm doing is using a table that I've created in Dreamweaver. It is a real estate application in the end. I need to capture the property ID (MLS) number and then plug it into a search engine on a certain web page to then find a URL which will then be applied to the actual property address in the cell next to the MLS# cell as a hyperlink. The length of my table changes each and every time. Right now I'm starting with the first cell of the table 'captured', as in CTRL-A, before I run the macro. That seems to take care of that particular problem. Since I only do this task once a week, that's not such a terrible inconvenience.
I've got another issue, but that should be a new post.
Cheers!
Here's the code I'm currently using. I use Press Tab * 10 to get to the next cell where I need to capture the MLS#. Never thought of using the arrow keys for that particular navigation, though there's no reason that shouldn't work just as well. Nice idea; 2 steps instead of 10.
// C:\My Documents\Macro Scheduler\Reports.scp
// Recorded on Sunday, June 28, 2009, at 04:12 PM
//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
Let>k=0
Repeat>k
//1. Capture MLS# and post in browser search
MouseMove>92,17
Wait>1
LClick
Wait>0.2
MouseMove>129,161
Wait>1
LClick
Wait>0.2
MouseMove>643,1066
Wait>1
LClick
WaitWindowOpen>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM]
MoveWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],-5,-5
ResizeWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],1930,1054
Wait>0.2
MouseMove>1504,941
Wait>1
LClick
Wait>0.2
Press CTRL
Wait>0.2
Send>av
Wait>0.2
Release CTRL
Wait>.5
Press Enter
//2. Capture property URL & return to Dreamweaver
MouseMove>688,510
Wait>2.38
RClick
Wait>0.16
MouseMove>821,696
Wait>2.73
LClick
Wait>0.1
MouseMove>28,98
Wait>3.1
LClick
Wait>0.12
MouseMove>504,1065
Wait>2.6
LClick
WaitWindowOpen>Illustrated Properties Real Estate Inc. - Mozilla Firefox
MoveWindow>Illustrated Properties Real Estate Inc. - Mozilla Firefox,0,0
ResizeWindow>Illustrated Properties Real Estate Inc. - Mozilla Firefox,1920,1200
//3. Create hyperlink and move to next MLS#
MouseMove>429,139
Wait>2
Press Tab
Wait>0.47
MouseMove>191,18
Wait>1.95
LClick
Wait>0.12
MouseMove>254,346
Wait>1.95
LClick
WaitWindowOpen>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM]
MoveWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],-5,-5
ResizeWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],1930,1054
Wait>1.29
Press Tab
Wait>0.56
Press CTRL
Wait>0.27
Send>v
Wait>0.13
Release CTRL
Wait>0.59
Press Enter
WaitWindowOpen>Hyperlink
MoveWindow>Hyperlink,709,456
ResizeWindow>Hyperlink,503,289
Wait>0.99
Press Tab * 10
//Wait>0.44
//MouseMove>100,20
//Wait>3.7
//LClick
//Wait>0.13
//MouseMove>167,154
//Wait>2.22
//LClick
//Finish the Repeat/Until loop
//The Until>k= should be the number of times you want it to run
Let>k=k+1
Until>k=12
Thanks for the expanded explanation.
What I'm doing is using a table that I've created in Dreamweaver. It is a real estate application in the end. I need to capture the property ID (MLS) number and then plug it into a search engine on a certain web page to then find a URL which will then be applied to the actual property address in the cell next to the MLS# cell as a hyperlink. The length of my table changes each and every time. Right now I'm starting with the first cell of the table 'captured', as in CTRL-A, before I run the macro. That seems to take care of that particular problem. Since I only do this task once a week, that's not such a terrible inconvenience.
I've got another issue, but that should be a new post.
Cheers!
Here's the code I'm currently using. I use Press Tab * 10 to get to the next cell where I need to capture the MLS#. Never thought of using the arrow keys for that particular navigation, though there's no reason that shouldn't work just as well. Nice idea; 2 steps instead of 10.
// C:\My Documents\Macro Scheduler\Reports.scp
// Recorded on Sunday, June 28, 2009, at 04:12 PM
//Recorded Events
Let>WW_TIMEOUT=5
CapsOff
Let>k=0
Repeat>k
//1. Capture MLS# and post in browser search
MouseMove>92,17
Wait>1
LClick
Wait>0.2
MouseMove>129,161
Wait>1
LClick
Wait>0.2
MouseMove>643,1066
Wait>1
LClick
WaitWindowOpen>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM]
MoveWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],-5,-5
ResizeWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],1930,1054
Wait>0.2
MouseMove>1504,941
Wait>1
LClick
Wait>0.2
Press CTRL
Wait>0.2
Send>av
Wait>0.2
Release CTRL
Wait>.5
Press Enter
//2. Capture property URL & return to Dreamweaver
MouseMove>688,510
Wait>2.38
RClick
Wait>0.16
MouseMove>821,696
Wait>2.73
LClick
Wait>0.1
MouseMove>28,98
Wait>3.1
LClick
Wait>0.12
MouseMove>504,1065
Wait>2.6
LClick
WaitWindowOpen>Illustrated Properties Real Estate Inc. - Mozilla Firefox
MoveWindow>Illustrated Properties Real Estate Inc. - Mozilla Firefox,0,0
ResizeWindow>Illustrated Properties Real Estate Inc. - Mozilla Firefox,1920,1200
//3. Create hyperlink and move to next MLS#
MouseMove>429,139
Wait>2
Press Tab
Wait>0.47
MouseMove>191,18
Wait>1.95
LClick
Wait>0.12
MouseMove>254,346
Wait>1.95
LClick
WaitWindowOpen>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM]
MoveWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],-5,-5
ResizeWindow>Adobe Dreamweaver CS4 - [June 2009 PGA Current.HTM],1930,1054
Wait>1.29
Press Tab
Wait>0.56
Press CTRL
Wait>0.27
Send>v
Wait>0.13
Release CTRL
Wait>0.59
Press Enter
WaitWindowOpen>Hyperlink
MoveWindow>Hyperlink,709,456
ResizeWindow>Hyperlink,503,289
Wait>0.99
Press Tab * 10
//Wait>0.44
//MouseMove>100,20
//Wait>3.7
//LClick
//Wait>0.13
//MouseMove>167,154
//Wait>2.22
//LClick
//Finish the Repeat/Until loop
//The Until>k= should be the number of times you want it to run
Let>k=k+1
Until>k=12
Use if statements
Hi GalaxyMan,
If I understand correctly, in step #1 within the repeat loop you move the mouse to 1504,941 and LClick to activate the first cell. On subsequent passes through the loop you do not want to move the mouse since you already used the Press Tab *10 in step#3 to move the cursor to the second cell.
Try this replacing the MouseMove with this code in step #1:
Gale
If I understand correctly, in step #1 within the repeat loop you move the mouse to 1504,941 and LClick to activate the first cell. On subsequent passes through the loop you do not want to move the mouse since you already used the Press Tab *10 in step#3 to move the cursor to the second cell.
Try this replacing the MouseMove with this code in step #1:
Code: Select all
if>k=0
MouseMove>1504,941
else
//Cursor on next row already, but maybe not activated
endif
//The subsequent LClick should activate the cell were the cursor is.
Gale
Re: Use if statements
Hi, Gale,gdyvig wrote:Hi GalaxyMan,
If I understand correctly, in step #1 within the repeat loop you move the mouse to 1504,941 and LClick to activate the first cell. On subsequent passes through the loop you do not want to move the mouse since you already used the Press Tab *10 in step#3 to move the cursor to the second cell.
Try this replacing the MouseMove with this code in step #1:
Code: Select all
if>k=0 MouseMove>1504,941 else //Cursor on next row already, but maybe not activated endif //The subsequent LClick should activate the cell were the cursor is.
Gale
Sorry to be so long replying, but life is busy...
I discovered something quite by accident in trying to resolve this problem.
The reason it kept going back to the same starting point was because I was starting at a point with absolute mouse position variables. Once I got rid of that and started from a situation where the text I wanted to deal with initially was selected, then it became easy to get around that, as I only had to start with a CTRL-C and then move on. At the end of the script, the last thing that it does is it highlights the next text to be copied, so that was nice to figure out.