I have recently written some code that reads figures from documents in a Lotus Notes database, does some simple calculations with them and exports the results to a table in a Word document. Every now and then I get a Notes error message saying:
"Microsoft Word: Cannot access individual columns in this collection because the table has mixed cell widths".
The infuriating thing is that this appears from nowhere. I can use the export plenty of times with no problems and then next time I come back to it, it gives me this message. If I leave it for a while, there's a very good chance it'll go away again. If I comment out the lines that set the column widths, it solves it every time but of course the table is now out of proportion.
Here's the basic setup of the Word doc in the code:
[VBA]'create Word document
Set wdApp = CreateObject("Word.Application")
Set worddocument = wdApp.Documents.Add()
wdApp.visible = True
worddocument.pagesetup.Orientation = wdOrientPortrait
.selection.typetext("Total Costs for Current Projects")
'and so forth...
'create 3-column table to with catcount+2 rows (including title and total rows)
Set TableObj = .selection.Tables.Add(wdApp.Selection.Range, catcount+2, 3)
'set all column widths as appropriate
TableObj.Columns(1).Width = 260 'commenting out these 3 lines always fixes it
TableObj.Columns(2).Width = 90
TableObj.Columns(3).Width = 90
I have no idea why it works sometimes and not others. I'm not changing anything and I'm using the same test data every time so why is it so temperamental? It was working fine this morning but as I write this, it's gone haywire again. Help! I know Notes is sometimes funny with VBA...can I just put it down to that? I would like to be able to guarantee it won't happen again though.
Any suggestions appreciated. Thanks!