Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch Save as txt-utf-8

Status
Not open for further replies.

richiwatts

Technical User
Jun 21, 2002
180
GB
Hi,

I have been trying to play around with the Macro recoder without success.

If I have 30 Doc files open how can I batch "Save as" txt with UTF-8 encoding on all the open files?

Rich
 

Something like this ought to get you started ...

Code:
For Each doc in Documents
    doc.SaveAs FileName:=Left(doc.Name, InStrRev(doc.Name, ".") - 1) & ".txt", _
               FileFormat:=wdFormatText, _
               Encoding:=msoEncodingUTF8
Next

You may want to add more options to the save depending on your requirements.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
I sort of have it working. I just have 2 issues.

1. It saves them in My Documents and not in the current folder where the file is saved.
2. It adds the BOM (Byte order mark). Is it possible to remove the BOM

Code:
Sub SaveAsUTF()
'
' SaveAsUTF Makro
' Makro inspelat 2007-02-22 av chrisp
'
For Each doc In Documents
    doc.SaveAs FileName:=Left(doc.Name, InStrRev(doc.Name, ".") - 1) & ".txt", _
        FileFormat:=wdFormatText, _
        LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False, Encoding:=65001, InsertLineBreaks:=False, AllowSubstitutions:= _
        False, LineEnding:=wdCRLF, AddBiDiMarks:=False
Next
End Sub
 
Replace doc.Name with doc.FullName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks that worked.

Do you have any idea how I can remove the BOM (Byte order mark) that Word adds to the file.
 
Because when you save as text UTF-8 it is really UTF-8Y
and this means the BOm is there. I have to use a BOM remover tool to get rid of it as our server application doesn't work properly when it is there.

 
Ah yes, I remember now. In theory should it not be ignored by compliant applications?

It would be possible to post process it within VBA and delete the first three bytes - in effect, presumably, what your tool does; I don't know if there's a better option. I don't have time to play with it at the moment (perhaps next week) but opening it as a stream would allow any action you want.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top