Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Sorry - searched and search but keep finding messages to links to the old board and getting 404's on those links.

    (like this one)
    http://windowssecrets.com/forums/sho...-Word-2003-SP2

    I'm trying the following macro but doesn't seem to work. Can anyone help?
    Would be nice to pick a source folder and a target folder each time, but beggars can't be choosers. Thanks!


    Code:
    Sub ProcessFiles()
    'RTF Macro'
    ' Edit as needed, but keep trailing backslashes
    Const strSourcePath = "C:DOC"
    Const strTargetPath = "C:RTF"
    Dim strFile As String
    Dim doc As Document
    
    On Error GoTo ErrHandler
    
    strFile = Dir(strSourcePath & "*.rtf")
    Do While Not strFile = ""
    Set doc = Documents.Open(FileName:=strSourcePath & strFile, AddToRecentFiles:=False)
    doc.SaveAs FileName:=strTargetPath & strFile, FileFormat:=wdFormatRTF
    doc.Close SaveChanges:=wdDoNotSaveChanges
    strFile = Dir
    Loop
    
    ExitHandler:
    Set doc = Nothing
    Exit Sub
    
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    There were a few things wrong with your code so here is the refreshed macro

    Firstly, the paths needed to keep the trailing backslashes (as it says in the comment). Secondly, you were looking for rtf files in the doc folder. Finally, I took off the file suffix to replace it with the rtf extension
    Code:
    Sub ProcessFiles()  'RTF Macro'
      ' Edit as needed, but keep trailing backslashes
      Const strSourcePath = "C:\DOC\"
      Const strTargetPath = "C:\RTF\"
      Dim strFile As String, strFileAbbrev As String
      Dim doc As Document
      
      On Error GoTo ErrHandler
      
      strFile = Dir(strSourcePath & "*.doc")
      Do While Not strFile = ""
        strFileAbbrev = Left(strFile, InStr(strFile, ".doc") - 1)
        Set doc = Documents.Open(FileName:=strSourcePath & strFile, AddToRecentFiles:=False)
        doc.SaveAs FileName:=strTargetPath & strFileAbbrev, FileFormat:=wdFormatRTF
        doc.Close SaveChanges:=wdDoNotSaveChanges
        strFile = Dir
      Loop
      
    ExitHandler:
      Set doc = Nothing
      Exit Sub
      
    ErrHandler:
      MsgBox Err.Description, vbExclamation
      Resume ExitHandler
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks Andrew. This works great!

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    You could also adapt the code to prompt for folder paths.

    Here is one way of doing this - note that you need to get the additional code for a second module
    http://www.ammara.com/access_image_f...er_dialog.html
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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