Sub SaveToUTF8(sSourceFile As String)
Dim MyDoc As Document
Dim sTargetFile$, i&
If Dir(sSourceFile) = "" Then MsgBox sSourceFile & " not exists": Exit Sub
i = InStrRev(sSourceFile, ".")
sTargetFile = Left(sSourceFile, i - 1) & "_ToUtf8" & Right(sSourceFile, Len(sSourceFile) - i + 1)
Set MyDoc = Documents.Open(FileName:=sSourceFile, ConfirmConversions:=False, AddToRecentFiles:=False, _
Revert:=False, Format:=0, Visible:=False)
With MyDoc
If .OpenEncoding = 65001 Then MsgBox "This is a UTF8-encoded text file!": .Close: Exit Sub
.SaveAs FileName:=sTargetFile, fileformat:=7, Encoding:=65001
.Close
End With
End Sub
|