Setting text encoding in Word

R

raymondino

I work with text files in different languages each encoded accordingly. When I choose File->Open in Word I get a dialog box titled "Convert File" where I select "Encoded Text". Then I get a dialog titled "File Conversion" where I can choose the language encoding and see a preview of my file.

The above is what I want, but my macro will not replicate this behavior.
I have:
Documents.Open FileName:=myFilePath, ConfirmConversions:=True

And I get the first "Convert File" box, but when I choose "Encoded Text" no second dialog appears, and the file is opened with the default encoding, ie incorrect.

Does anyone know how to make the second "File Conversion" dialog appear so I can select the encoding?

Any help appreciated
 
S

Stefan Blom

When you call the Open method, use the Format and Encoding arguments
rather than the ConfirmConversions argument:

From Word VBA Help:********************
Format Optional Variant. The file converter to be used to open the
document. Can be one of the following WdOpenFormat constants:
wdOpenFormatAllWord, wdOpenFormatAuto, wdOpenFormatDocument,
wdOpenFormatEncodedText, wdOpenFormatRTF, wdOpenFormatTemplate,
wdOpenFormatText, wdOpenFormatUnicodeText, or wdOpenFormatWebPages.
The default value is wdOpenFormatAuto.

Encoding Optional Variant. 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 is the system code page. Read/write Long.
***************************************

Does this help?

--
Stefan Blom


raymondino said:
I work with text files in different languages each encoded
accordingly. When I choose File->Open in Word I get a dialog box
titled "Convert File" where I select "Encoded Text". Then I get a
dialog titled "File Conversion" where I can choose the language
encoding and see a preview of my file.
The above is what I want, but my macro will not replicate this behavior.
I have:
Documents.Open FileName:=myFilePath, ConfirmConversions:=True

And I get the first "Convert File" box, but when I choose "Encoded
Text" no second dialog appears, and the file is opened with the
default encoding, ie incorrect.
Does anyone know how to make the second "File Conversion" dialog
appear so I can select the encoding?
 
R

raymondino

Hi Stefan

thanks for the post. But I cannot use the Encoding & Format arguments as they are all text files with different encoding for each file. The reason I need the second dialog (Encoding Picker) is precisely to set the encoding.

Anyway, I found the answer:
There is another argument for the Open method: NoEncodingDialog
Although the default value is False, you have to set this explicitly:

Documents.Open FileName:=MyFilePath, ConfirmConversions:=True, NoEncodingDialog:=False

Hey presto, the encoding selection I need.
 
S

Stefan Blom

I'm glad that you found a solution.

FWIW, I'm still on Word 2000; in this version, there seems to be no
NoEncodingDialog argument for the Open method of the Documents
collection.

--
Stefan Blom


raymondino said:
Hi Stefan

thanks for the post. But I cannot use the Encoding & Format
arguments as they are all text files with different encoding for each
file. The reason I need the second dialog (Encoding Picker) is
precisely to set the encoding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top