Function ConvertWordDocument(ByVal sFilename As String, _ Optional ByVal wdFormat As WdSaveFormat = wdFormatText, _ Optional ByVal sNewFileName As String) As Boolean Dim iPointer As MousePointerConstants Dim sExtension As String Dim oWord As New Word.Application
On Error GoTo ErrHandler iPointer = Screen.MousePointer oWord.Documents.Open sFilename, False, False, False, , , , , , _ wdOpenFormatAuto If Len(sNewFileName) = 0 Then sNewFileName = sFilename If InStr(sNewFileName, ".") > 0 Then sNewFileName = Left$(sNewFileName, _ InStr(sNewFileName, ".") - 1) sExtension = Switch(wdFormat = wdFormatDocument, ".doc", _ wdFormat = wdFormatDOSText, ".txt", _ wdFormat = wdFormatDOSTextLineBreaks, ".txt", _ wdFormat = wdFormatEncodedText, ".txt", wdFormat = wdFormatHTML, _ ".htm", wdFormat = wdFormatRTF, ".rtf", wdFormat = wdFormatTemplate, _ ".doc", wdFormat = wdFormatText, ".dot", _ wdFormat = wdFormatTextLineBreaks, ".txt", _ wdFormat = wdFormatUnicodeText, ".txt") sFilename = sFilename & sExtension End If oWord.ActiveDocument.SaveAs sNewFileName, wdFormat, , , False oWord.Quit Set oWord = Nothing
ConvertWordDocument = True ErrHandler: Screen.MousePointer = iPointer End Function |