|
-
July 12th, 2001, 08:23 AM
#1
Disappearing Table in MS Word
I've got a program that outputs data by creating a Word document with a big table. I create the document and the table and all the data in it from my code. It all works fine the first time I try it, but if I generate a second or third etc report, the table is not created but the data in the table is sent anyway. I get no error messages, only a lot of data piled up that should be organized into a table that isn't there. Any ideas?
'create instance of word
Dim wrdapp
'check to see if wrdapp object is already instantiated
'if so, move on. if not, then set it to Word.Application
on error resume next
Err = 0
a = wrdapp.Visible
If Err = 462 then
set wrdapp = new Word.Application
End If
Err = 0
wrdapp.Visible = false
If Err <> 0 then
wrdapp.Quit
set wrdapp = new Word.Application
wrdapp.Visible = false
End If
'add a document to Word
wrdapp.Documents.Add
'create the table
'THIS PART ONLY WORKS on THE FIRST ATTEMPT
'THE ONLY WAY to MAKE IT WORK AGAIN is to EXIT MY
'APP, then IT WILL WORK ONCE AGAIN UNTIL I EXIT
'AGAIN.
wrdapp.Selection.Tables.Add Range:=Selection.Range, NumRows:=21, NumColumns _
:=5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
wrdapp.Selection.Tables(1).AutoFormat Format:=wdTableFormatContemporary, _
ApplyBorders:=true, ApplyShading:=true, ApplyFont:=true, ApplyColor:=true _
, ApplyHeadingRows:=true, ApplyLastRow:=false, ApplyFirstColumn:=true, _
ApplyLastColumn:=false, AutoFit:=true
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|