Does anyone have an example of how to read in a text file and export it to a Word document (from a VB program) ?
Thanks for any help....
Printable View
Does anyone have an example of how to read in a text file and export it to a Word document (from a VB program) ?
Thanks for any help....
Do you want the example in VB6 or Visual Basic for Applications (VBA)?
Here is an example in VB6 (wrong Forum of course - but in accordance with your request :))
VB Code:
Option Explicit 'Reference Word Object Library 9.X Private Sub form_load() Dim objWord As Word.Application Dim objDoc As Word.Document On Error GoTo Err_Handler Set objWord = New Word.Application Set objDoc = objWord.Documents.Open("C:\test1.txt") objWord.Visible = True Set objDoc = Nothing Set objWord = Nothing Exit Sub Err_Handler: If Not (objDoc Is Nothing) Then Set objDoc = Nothing If Not (objWord Is Nothing) Then Set objWord = Nothing MsgBox "Number: " & Err.Number & vbCrLf & _ "Description: " & Err.Description, vbOKOnly + vbCritical, "Error!" End Sub
Beautiful ! Thank you !
I just need one more thing.... a command to save the file as a name that I would like to specify.
Thanks!
I found it:
objDoc.SaveAs ("mynewfilename.doc")
But I want to add some object of MSWord such as : table, header & footer, line,... into this DOC file. How can I do? Can U help me? thanksQuote:
Originally Posted by Bruce Fox