Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Dec 2002
    Location
    San Francisco, California, USA
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batch convert files from .rtf to .doc? (Word 2003)

    I have dozens of files on my computer that have .doc extensions, but in fact are in .rtf format. (It's a peculiarity of the way Westlaw provides files for download.) For a couple of reasons, I need to convert these files all to actual .doc formats.* I know I can do this by opening each individual file, doing a FILE - SAVE AS, and just changing the file type designation from Rich Text to Word. But I'm wondering if there's a way to automate this process.....

    *Reasons: (1) My desktop search engine (copernic) can't index files that are like this; (2) I need to make use of some of the document property features that are available in an actual Word 2003 .doc file, and that are not available in these .rtf files.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Batch convert files from .rtf to .doc? (Word 2003)

    You could put all those files in a folder (without other .doc files), and use a macro to process all .doc files in that folder. The target folder should be different from the source folder to avoid confusion.

    Sub ProcessFiles()
    ' Edit as needed, but keep trailing backslashes
    Const strSourcePath = "C:RTF"
    Const strTargetPath = "C:Word"
    Dim strFile As String
    Dim doc As Document

    On Error GoTo ErrHandler

    strFile = Dir(strSourcePath & "*.doc")
    Do While Not strFile = ""
    Set doc = Documents.Open(FileName:=strSourcePath & strFile, AddToRecentFiles:=False)
    doc.SaveAs FileName:=strTargetPath & strFile, FileFormat:=wdFormatDocument
    doc.Close SaveChanges:=wdDoNotSaveChanges
    strFile = Dir
    Loop

    ExitHandler:
    Set doc = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Dec 2002
    Location
    San Francisco, California, USA
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch convert files from .rtf to .doc? (Word 2

    Thanks. I get an error message when the macro reaches the "Set doc =" line (Word pops up a box that says "this is not a valid file name"). I don't really understand what the Set statement does, so I can't figure out what's going wrong. I did check, and "strSourcePath & StrFile" does yield a string, in quotes, that contains the full name of a file in the appropriate folder. So that's not the problem. Any ideas????

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Batch convert files from .rtf to .doc? (Word 2

    The set doc = ... line opens a document and makes the doc variable refer to this document. I have tested the code, it works correctly. So there must be something wrong with the path and/or file name. Have you included the backslash at the end of the strSourcePath variable? And are you absolutely sure that there is no typing error in this variable?

  5. #5
    2 Star Lounger
    Join Date
    Dec 2002
    Location
    San Francisco, California, USA
    Posts
    108
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batch convert files from .rtf to .doc? (Word 2

    I assumed that's what it did., but I still don't see the problem. I didn't modify your code in any way. All I did is create two new folders under my c: drive, one called "rtf" and one called "doc," to match your constants, and then I copies some files into the .rtf folder, and stepped through the macro. So, the filenames are all regular filenames, the directories are the same as the ones designated in the macro, but the thing doesn't work.

    I WAS able to modify it by deleting the most of the code in the do-loop, and and replacing it as below. Does my code do the same stuff as your code, just w/different statements, or is mine really weird?

    Do While Not strFile = ""
    TempName = strSourcePath & strFile
    Documents.Open FileName:=TempName
    ActiveDocument.SaveAs FileFormat:=wdFormatDocument
    ActiveDocument.Close
    ' Set doc = Documents.Open(FileName:=strSourcePath & strFile, AddToRecentFiles:=False)
    ' doc.SaveAs FileName:=strTargetPath & strFile, FileFormat:=wdFormatDocument
    ' doc.Close SaveChanges:=wdDoNotSaveChanges
    strFile = Dir

    thanksf for your help.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Batch convert files from .rtf to .doc? (Word 2

    In my example code, the target folder was named 'Word', not 'doc'. If you named it 'doc' but kept 'Word' in the code, you would get an error message.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •