Hi All.
Learning Word automation, this what I have found/learned so far during my searching:
Class Variables:
CODE
Dim oWord As Microsoft.Office.Interop.Word.Application
Dim oDoc As Microsoft.Office.Interop.Word.Document
Dim oPar As word.Range
Code in Function that is carried out by background worker:
CODE
Try
oWord = New word.Application
oWord = CType(CreateObject("Word.Application"), word.Application)
oDoc = oWord.Documents.Add(Template:=txtFolderLoc.Text & "\Report.dot")
Dim save As Object = False
Dim dest As Object = txtFolderLoc.Text & "\"
For Each item In ListBox2.Items.ToString
oPar.Text = item
Next
oWord.Visible = True
oDoc.SaveAs(dest & txtFileName.Text)
oWord.Quit(save)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return oWord
It opens the template, print the last listbox2.item instead of all the items (maybe the listbox.items.tostring problem)otherwise it is working fine. One time while it was loading I noticed all the items printed to the same line overwriting each other til it printed the last .items printed to the file. What am I missing???