Dear All,
I am trying to create word documents from my VB6 application but I am having trouble trying to close MS Word. The following code prints and saves the document OK but leaves an instance of WINWORD.EXE in my task list. Each time I execute the code another instance is added to the list.
Public Function BuildDoc(UniqueID As String)
Dim cnx As New ADODB.Connection
Dim RS1 As ADODB.Record
Dim savfilename As String
'
Set WA = New Word.Application
WA.Visible = False
On Error GoTo DocError
'
savfilename = "c:\Filename" & UniqueID & ".doc"
'
Documents.Add
'
Selection.Font.Size = 14
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Details for file " & UniqueID
Selection.TypeParagraph
Selection.TypeParagraph
'
ActiveDocument.PrintOut
'
ActiveDocument.SaveAs (savfilename)
'
ActiveDocument.Close
'
Set WA = Nothing
Exit Function
DocError:
MsgBox ("Document Error - " & Err.Number)
Exit Function
Set WA = Nothing
End Function
Can anybody help?
I am trying to create word documents from my VB6 application but I am having trouble trying to close MS Word. The following code prints and saves the document OK but leaves an instance of WINWORD.EXE in my task list. Each time I execute the code another instance is added to the list.
Public Function BuildDoc(UniqueID As String)
Dim cnx As New ADODB.Connection
Dim RS1 As ADODB.Record
Dim savfilename As String
'
Set WA = New Word.Application
WA.Visible = False
On Error GoTo DocError
'
savfilename = "c:\Filename" & UniqueID & ".doc"
'
Documents.Add
'
Selection.Font.Size = 14
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Details for file " & UniqueID
Selection.TypeParagraph
Selection.TypeParagraph
'
ActiveDocument.PrintOut
'
ActiveDocument.SaveAs (savfilename)
'
ActiveDocument.Close
'
Set WA = Nothing
Exit Function
DocError:
MsgBox ("Document Error - " & Err.Number)
Exit Function
Set WA = Nothing
End Function
Can anybody help?