|
-
Dec 17th, 2005, 04:08 PM
#1
Thread Starter
Addicted Member
Create Word Document from Text File
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....
-
Dec 18th, 2005, 08:40 PM
#2
Re: Create Word Document from Text File
Do you want the example in VB6 or Visual Basic for Applications (VBA)?
-
Dec 18th, 2005, 08:46 PM
#3
Re: Create Word Document from Text File
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
-
Dec 19th, 2005, 10:20 AM
#4
Thread Starter
Addicted Member
Re: Create Word Document from Text File
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!
-
Dec 19th, 2005, 10:27 AM
#5
Thread Starter
Addicted Member
Re: Create Word Document from Text File
I found it:
objDoc.SaveAs ("mynewfilename.doc")
-
Jan 6th, 2006, 11:36 AM
#6
Lively Member
Re: Create Word Document from Text File
 Originally Posted by Bruce Fox
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
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? thanks
!Have fun!

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|