Macro for a WORD97 table

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
wdc
Junior Coder
Posts: 33
Joined: Mon Jun 09, 2003 1:37 am
Location: Chevy Chase Maryland

Macro for a WORD97 table

Post by wdc » Sat Jun 10, 2006 11:33 am

I have owned MS 6.2 for years but have never really used it for any complex macros. Could someone please help me write a macro for this application?

PROBLEM: I have a WORD97 file (Table.doc) containing a table with 3 columns (A, B, and C) and 600 rows. The cells in Column A are initially all blank. Each cell in Columns C and D contains a 6-digit number.

I want the macro to:

1. Check to see if the number in cell B1 appears anywhere in Column C.
If it does, then I want to place a mark (X) in cell A1
If the number in B1 does not appear anywhere in Column C then I want to place a different mark (Y) in cell A1.

2. Then I want to repeat the check-and-mark operation for the numbers in cells B2, B3, …, B600.


In particular, what command do I use to tell MS to:
a. Goto cell B1 in file Table.Doc?
b. Highlight the number in that cell?
c. Then go to Column C and find that same number in Column C
d. Print an X or a Y in cell A1?

Thanks. …wdc

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon Jun 12, 2006 2:41 pm

Are you stuck with using Word? That the kind of thing Excel excels at (without needing a macro)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 13, 2006 6:08 pm

I agree with Me_again. On the other hand I needed something else to think about over lunch today and this seemed like a good diversion.

This will work if the table is set up as you described. Column A is empty,
Column B has data and each column B item is compared to each column C item. If there is a match, an "X" is written in column A in the column B match row. If there is not a match found a "Y" is written in column A in the column B non-match row.

- Paste this script into a macro and assign a "hot key" to the macro.
- Open your Word document
- select a table item
- press the hot key combination
- Wait
- Be careful not to lose focus on the word document

With 600 items this will take a while. Excel would do this in seconds, this macro will take forever by comparison.

This will not work in Macro Scheduler version 6. You will need to upgrade or at least download the latest evaluation version.

Lunch hour is over.
Good Luck,
Dick

Code: Select all

Press CTRL
Send>a
Release CTRL
Wait>0.5
Press CTRL
Send>c
Release CTRL
Wait>0.5
Press up
Wait>0.5
Press CTRL
Press HOME
Release CTRL

GCB>table
Separate>table,%CRLF%,row
Let>k=0
Repeat>k
  add>k,1
  Let>value=row_%k%
  Separate>value,%TAB%,row_%k%_col
Until>k,row_count

Let>kk=0
Repeat>kk
  add>kk,1
  Let>kkk=0
  Let>col_count=row_%kk%_col_count
  If>%col_count%=0,done
  Let>value=row_%kk%_col_2
  Repeat>kkk
    add>kkk,1
	Let>find=row_%kkk%_col_3
	If>%find%=%value%
	  //Let>row_%kk%_col_1=X
	  Send>X
	  Press Down
	EndIf
  Until>kkk,row_count
  Let>value=row_%kk%_col_1
  If>%value%=
    //Let>row_%kk%_col_1=Y
	Send>Y
	Press Down
  EndIf
  Label>done
Until>kk,row_count

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