Bazango
02-14-2006, 04:24 PM
I am trying to apply my Word 2003's scripting behavior to bulk convert some Word based HTML to text. I first started with Windows Script Hosting, had some problems and finally worked my way to Word's internal scripting capability and had the same problem.
Here is the subroutine as I run it in Word:
Sub OpenDoc2()
Documents.Open _
ReadOnly:=False, _
FileName:="C:\....\MyDocFile.doc", _
Format:=wdOpenFormatDocument
ActiveDocument.SaveAs _
FileName:="C:\...\MyTextFile.txt", _
FileFormat:=wdSaveFormatText
On Error GoTo errorHandler
ActiveDocument.Close
errorHandler:
If Err = 4198 Then MsgBox "Document was not closed"
End Sub
The important part is in red. Nothing happens. When I open MyTextFile.txt, I see a lot of gibberish. If I open the document in Word, the original formatting and font are intact. If I save the file as Plain Text from Word the usual way, I get plain text.
Here is how to duplcate this effort:
Open Word with a new document.
Open Word which will load a new document.
Use the "Tools" menu, go to Macro and choose Visual Basic Editor -- you might have to go back and install it.
From the VB Editor, select the Insert menu and choose Class Module.
Cut and paste the code I include here.
Create a test document in word and place the location and name in the correct C:/.../MyDocFile.doc location in the code.
Insert a location and name for the file you want the macro to create in the correct C:/.../MyTextFile.txt location in the code.
Save the document.
In the Run menu choose Run to run the Macro.
Any and all tips or clues would be appreciated.
Here is the subroutine as I run it in Word:
Sub OpenDoc2()
Documents.Open _
ReadOnly:=False, _
FileName:="C:\....\MyDocFile.doc", _
Format:=wdOpenFormatDocument
ActiveDocument.SaveAs _
FileName:="C:\...\MyTextFile.txt", _
FileFormat:=wdSaveFormatText
On Error GoTo errorHandler
ActiveDocument.Close
errorHandler:
If Err = 4198 Then MsgBox "Document was not closed"
End Sub
The important part is in red. Nothing happens. When I open MyTextFile.txt, I see a lot of gibberish. If I open the document in Word, the original formatting and font are intact. If I save the file as Plain Text from Word the usual way, I get plain text.
Here is how to duplcate this effort:
Open Word with a new document.
Open Word which will load a new document.
Use the "Tools" menu, go to Macro and choose Visual Basic Editor -- you might have to go back and install it.
From the VB Editor, select the Insert menu and choose Class Module.
Cut and paste the code I include here.
Create a test document in word and place the location and name in the correct C:/.../MyDocFile.doc location in the code.
Insert a location and name for the file you want the macro to create in the correct C:/.../MyTextFile.txt location in the code.
Save the document.
In the Run menu choose Run to run the Macro.
Any and all tips or clues would be appreciated.