Re: how to close word object
Because your destroying the document object before adding the table to it. - Set doc = Nothing
;)
Re: how to close word object
i do that but it's still the same
Re: how to close word object
Your logic is not that good. You dont need to keep a app object var local to the procedure and set it and then destroy it every button click. If you need your app object available across several procedures then it would be better to have them module level vars so you dont need to keep doing a set/destory/set in every procedure.
Re: how to close word object
VB Code:
Private objWord As Word.Application
Private Sub Command12_Click()
Dim doc As Word.Document
objWord.ActiveDocument.Close
objWord.Quit 'Why quit if your using it again?
Set objWord = Nothing
Set objWord = New Word.Application 'Why create again?
Set objWord = GetObject(, "Word.application") 'Why recreate after being set in previous line?
objWord.Visible = True
Set doc = objWord.Documents.add()
doc.Activate
Set doc = Nothing 'Destroying righ after being set?
With objWord.Selection
.Tables.add Range:=Selection.Range, NumRows:=5, NumColumns:=1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
.TypeText "{ifra" & vbTab & vbTab & "m2" & vbTab & vbTab & "Cena" & vbTab & vbTab & "Kat" & vbTab & vbTab & "Naselba" & vbTab & vbTab & "Grad"
End With 'Not in you code, missing
End Sub