Fill data in Word Table or Execute VBScript in Word via COM

Hi folks,

I’m currently working on a report that must be produced in Word. The template consists out of several word tables.

I figured out how to address the tables and place the cursor in the first cell of each table. But I couldn’t find a way to move from cell to cell.

If anyone did this already, could you please put a peace of code here to let me know how you did it?

The workaround I tried, was to move the cursor by calling a VBScript in Word - but it seems as if this doesn’t work at all! Did anyone figure out how to start a VBScript in Word via COM? - I do this regularly in Excel - but word causes my natural progam to say that the given Macro can not be executed (NAT0720 DCOM server message).

Any idea, help, code sample, hint… is highly appreciated!

Kind regards,

Stefan

Can you use the Cell interface to navigate ?

Hi Wolfgang,

You made my day!

Yes, it works with the cell interface, leaving the cells collection out…

This code works now - and as it might help searching folks to get along faster, I post it here, if that’s OK:

FOR ITAB = 1 TO 10 /* Table iteration
SEND METHOD “item” TO WORDTABLES WITH ITAB RETURN WORDTAB /* Select Table number ITAB
FOR COM-ROW = 4 TO 20
FOR COM-COL = 3 TO 5
Send Method “Cell” TO WORDTAB with COM-ROW COM-COL RETURN WORDCELL GIVING COM-RC /* Select a single cell
WORDRANGE:=WORDCELL.RANGE /* Set Wordrange to selected cell
MOVE #TABFUELL TO WORDRANGE.TEXT /* Fill Wordrange (Cell) with text
END-FOR
END-FOR
END-FOR

So the one thing left is, how to start a word macro from natural.

The following does NOT work:

  • COMPRESS DOC-FILE '!moveright' TO cMakros LEAVING NO
    
    cMakros := “Project.Modul1.moveright”
    Send Method “Run” TO WORDAPPL WITH cMakros

I tried both, the top part (Compress) how it would work within Excel - but neither this nor the style I found (and that works) to start word macro out of Excel does work here.

Do you have any idea?

Kind regards,

Stefan

Any news?
Does anyone have experience in calling word macros from within Natural?
Any help is highly appreciated!
Thx,
Stefan