ConvertWordDocument – Convert a Microsoft Word DOC file to another format

' Convert a Word-compatible format to an other format.' Parameters:'  - sFileName is the file to convert'  - wdFormat is the destination file's format'  - sNewFileName is the destination file. If not specified the the routine ' will use the sFileName's path & name'' NOTE: requires the Microsoft Word type library'' Example: convert from DOC to HTML'   ConvertWordDocument("C:DocumentsMyWordFile.doc", wdFormatHTML)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        ' open the file    oWord.Documents.Open sFilename, False, False, False, , , , , , _        wdOpenFormatAuto        ' the destination filename if sFileName is sNewFileName is missing    If Len(sNewFileName) = 0 Then        sNewFileName = sFilename        ' remove the actual extension ad add the one specified by sExtension        If InStr(sNewFileName, ".") > 0 Then sNewFileName = Left$(sNewFileName, _            InStr(sNewFileName, ".") - 1)        ' set the extension for the selected destination format        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")        ' add the extension to the file name        sFilename = sFilename & sExtension    End If        ' save the file    oWord.ActiveDocument.SaveAs sNewFileName, wdFormat, , , False        ' close Word    oWord.Quit    Set oWord = Nothing    ConvertWordDocument = True    ErrHandler:    ' restore the original mouse pointer    Screen.MousePointer = iPointerEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may