Private Sub Command1_Click()
Dim dir_name As String
Dim file_name As String
Dim word_server As Word.Application
Screen.MousePointer = vbHourglass
DoEvents
file_name = txtFile.Text
If InStr(file_name, ".") > 0 Then file_name = _
Left$(file_name, InStr(file_name, ".") - 1)
dir_name = txtDirectory.Text
If Right$(dir_name, 1) <> "\" Then dir_name = dir_name _
& "\"
' Create the Word server object.
On Error GoTo OpenError
Set word_server = New Word.Application
On Error GoTo 0
' Open the file.
word_server.ChangeFileOpenDirectory dir_name
word_server.Documents.Open _
FileName:=file_name & ".doc", _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
Revert:=False, _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
' Save the file.
word_server.ActiveDocument.SaveAs _
FileName:=file_name & ".txt", _
FileFormat:=wdFormatText, _
LockComments:=False, _
Password:="", _
AddToRecentFiles:=True, _
WritePassword:="", _
ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, _
SaveFormsData:=False, _
SaveAsAOCELetter:=False
word_server.Quit
Set word_server = Nothing
Screen.MousePointer = vbDefault
MsgBox "Done"
Exit Sub
OpenError:
Screen.MousePointer = vbDefault
MsgBox "Error" & Str$(Error.Number) & _
" opening Word." & vbCrLf & _
Error.Description
End Sub
|