PDA

View Full Version : Force MS Word to Open and Save all Text Files in MS DOS encoding



swaggerbox
08-31-2016, 03:59 AM
I have hundreds of text files in a folder that's incorrectly formatted. I had to open each text file in MS Word. And to correct it, open in MS DOS encoding, search and replace all Non-ASCII and then save the file in the same MS DOS encoding. Any idea how to get started?

gmaxey
08-31-2016, 04:41 AM
For the Batch part you can start with:

http://gregmaxey.mvps.org/word_tip_pages/process_batch_folder_addin.html

swaggerbox
08-31-2016, 04:53 AM
Thanks Greg. What I'm really struggling is to force open the file in a set text encoding, e.g. MS-DOS encoding.



Sub myRoutine()
Dim file
Dim path As String

path = "C:\Reports\"

file = Dir(path & "*.txt")
Do While file <> ""
Documents.Open FileName:=path & file

'subroutine to force MS Word to open text in MS-DOS encoding
'search and replace non-ASCII characters to standard format
'save text file in MS-DOS encoding

file = Dir()
Loop
End Sub

gmaxey
08-31-2016, 09:48 AM
How are you opening it in MS-DOS encoding manually?

swaggerbox
09-01-2016, 05:15 AM
Hi Greg
First I open the text file in MS Word. Since the file is not in plain text format (or was not formatted as plain text), it prompts user to select a text encoding format. I select MS-DOS encoding instead of Windows format.

16987

gmaxey
09-01-2016, 03:00 PM
Your picture leads one to believe you want to open in Other encoding "Japanese"

For MS-DOS try

Documents.Open FileName:="db1.mdb, Encoding:=437