PDA

View Full Version : Problem with merging cells in Word table



let98007
08-09-2009, 12:17 PM
I'm trying to add a table to display data from a sql query at the end of a document. The first draft of the code is below. It evolved largely by trial and error so suggestions will be appreciated. (The syntax is correct for Visual FoxPro.)

SELECT cl13
nRows = RECCOUNT('cl13')
IF nRows < 1
RETURN
ENDIF

* oWord.ActiveDocument.Paragraphs.Space1 && not sure what this does...
* add(Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)
oTable = oWord.ActiveDocument.tables.add(oRange,nRows*3,2,1,1) && add a table 2 rows by 3 columns
SET STEP on
oTable.Columns.SetWidth(468,0)
oTable.Columns(1).SetWidth(345,0)
oTable.Columns(2).SetWidth(123,0)

WITH oTable
* remove borders
.borders.InsideLineStyle = wdLineStyleNone && none
.borders.OutsideLineStyle = wdLineStyleNone && none

* format data rows
.cell[1,1].range.paragraphformat.Alignment = wdAlignParagraphLeft && left
.cell[1,2].range.paragraphformat.Alignment = wdAlignParagraphLeft && left
FOR i = 1 TO nRows
j = (i*3) - 2
.cell[j,1].range.InsertAfter(prname)
.cell[j,2].range.InsertAfter(dpname)
.rows[j+1].cells.merge()
cText = 'Notes: '+IIF(EMPTY(frnotes),'',frstline(frnotes))
.cell[j+1,1].range.InsertAfter(cText)
SKIP
ENDFOR
FOR k = 1 TO 3*nRows STEP 3
.rows[k].Borders[wdBorderTop].Linestyle = wdLineStyleSingle
ENDFOR
ENDWITH



I'd like to keep the data from each record together (widow/orphan control.) How do I do that in VBA?

The variable cText holds the first line from a memo or Text field. It begins "Notes: " Ideally, I'd like to have just the word Notes appear in bold but I can't figure out how to do it in code. In fact, I can't do it manually! Whenever I select the word and click on Bold to format it, Word applies the style to the following 5 or 6 rows! I'm using Word 2007 and this seems to happen frequently unfortunately. I don't know if that's a bug or a feature but it's really irritating.