none
Convert text coding inmultiple files from txt to doc RRS feed

  • Question

  • I have a folder with 450 small txt files. They're named like 113.txt 114.txt 115.txt etc. For some reason they all have text coding Japanese (Shift-JIS). I want to:

    Change the text coding to Western European (Windows)

    Change the font to Times New Roman 11 

    Save in Word (doc) format (113.doc 114.doc 115.doc).

    I have found a Power Shell script that converts the files to Word format but I still need the text coding and the font changed.

    Any suggestions?

    Wednesday, February 5, 2014 8:45 AM

Answers

  • Hi Zafon

    Changing the font is no problem:

    ActiveDocument.Content.Font.Name = "Times New Roman"
    ActiveDocument.Content.Font.Size = 11

    You need to specify the encoding when the text file is opened. The Documents.Open method has an Encoding parameter you use for that. Here's the information from the Help file on it:

    "The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page."

    If you're unsure what you should use, try recording a macro when opening the document as a user and look at what Word writes.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Zafon Wednesday, February 5, 2014 11:20 AM
    Wednesday, February 5, 2014 9:17 AM
    Moderator

All replies

  • Hi Zafon

    Changing the font is no problem:

    ActiveDocument.Content.Font.Name = "Times New Roman"
    ActiveDocument.Content.Font.Size = 11

    You need to specify the encoding when the text file is opened. The Documents.Open method has an Encoding parameter you use for that. Here's the information from the Help file on it:

    "The document encoding (code page or character set) to be used by Microsoft Word when you view the saved document. Can be any valid MsoEncoding constant. For the list of valid MsoEncoding constants, see the Object Browser in the Visual Basic Editor. The default value is the system code page."

    If you're unsure what you should use, try recording a macro when opening the document as a user and look at what Word writes.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Zafon Wednesday, February 5, 2014 11:20 AM
    Wednesday, February 5, 2014 9:17 AM
    Moderator
  • Thanks, that solved the main problem. Now I just have to fgure out how to loop throuh all the txt files in the folder:) 
    Wednesday, February 5, 2014 11:21 AM