|
|
Title | Convert a .rtf or .txt file into a .doc file |
Description | This example shows how to convert a .rtf or .txt file into a .doc file in Visual Basic 6. |
Keywords | document, word, rtf, txt, doc, convert file |
Categories | Office, Files and Directories |
|
|
Use Word as a server. Load the file and save it in its new format.
The ConvertToDoc subroutine opens a file and saves it as a .doc file.
|
|
' Open a file and save it as a .doc file.
Private Sub ConvertToDoc(ByVal in_file As String, ByVal _
out_file As String)
Const FORMAT_DOC As Integer = 0
Dim word_server As Object ' Word.Application
Set word_server = CreateObject("Word.Application")
' Open the input file.
word_server.Documents.Open _
FileName:=in_file, _
ReadOnly:=False, _
AddToRecentFiles:=False
' Save the output file.
word_server.ActiveDocument.SaveAs _
FileName:=out_file, _
FileFormat:=FORMAT_DOC, _
LockComments:=False, _
AddToRecentFiles:=True
' Exit the server without prompting.
word_server.ActiveDocument.Close False
End Sub
|
|
|
|
|
|