Save text to Word Template...

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi All.

Got some bits a pieces during my quest to learn office automation, part of this works, it opens the template as a new doc1 of the template, prints the last listbox.item only, and then save the file in the appdata(?) file location, instead of the one I want, what am I missing???

Class variables:
VB.NET:
Dim oWord As Microsoft.Office.Interop.Word.Application
    Dim oDoc As Microsoft.Office.Interop.Word.Document
    Dim oPar As word.Range

Code in the save btn.:
VB.NET:
        Try
            oWord = 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

Thanks for the help...
 
Last edited:
Ok, what isn't mentioned is that this save file function is used by a backgroundWorker(due to slow speed it was causing), now I am getting a cross thread reference to the listbox, so I just started learning about this so I have no clue how to reference info from one thread to another. Help!!!
 
Back
Top