JoeDBugger
New Member
- Joined
- Apr 22, 2009
- Messages
- 9
Using Excel VBA, I want to process all Word documents in the working directory saving them in text format. The processing will include: (1) open a Word document, (2) save that Word document in MS DOS text format, and (3) quit Word. The following VBA Macro is invoked for each Word document:
The problem with the VBA code is with the statement:
The resultant file contains "garbage," of course. I need some mechanism to indicate the "FileFormat" to the ".SaveAs".
Thanks,
Code:
Sub ProcessWordDocument(ByVal psWorkbookCurrentWorkingDirectory As String, _
ByVal psNextFullChecklistFileName As String, _
ByVal psNextChecklistFileName As String)
Dim wdApplication As Word.Application
Dim wdDocument As Word.Document
On Error Resume Next
Set wdApplication = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'----+----+----+----+----+----+----+----+----+----+----+----+
' Word is NOT already running
'----+----+----+----+----+----+----+----+----+----+----+----+
Set wdApplication = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDocument = wdApplication.Documents.Open(psWorkbookCurrentWorkingDirectory & "\" & psNextFullChecklistFileName)
wdApplication.Visible = True
wdDocument.SaveAs psWorkbookCurrentWorkingDirectory & "\" & psNextChecklistFileName & ".txt"
wdDocument.Close
wdApplication.Quit
Set wdApplication = Nothing
Set wdDocument = Nothing
End Sub ' End Sub ProcessWordDocument
The problem with the VBA code is with the statement:
Code:
wdDocument.SaveAs psWorkbookCurrentWorkingDirectory & "\" & psNextChecklistFileName & ".txt"
The resultant file contains "garbage," of course. I need some mechanism to indicate the "FileFormat" to the ".SaveAs".
Thanks,