Consulting

Results 1 to 3 of 3

Thread: Select a file, export it to RTF

  1. #1

    Select a file, export it to RTF

    I'm having a difficult time writing a macro that will allow the user to select a .DOC file via a file open dialog box and export it to RTF. I've been trying to modify examples I've found that allow you to convert an entire folder's worth of files to a specific format, but I can't seem to manage it. Could someone please put together a quick and dirty example that I can work from?

    I'm trying to automate a process that involves one of my company's proprietary tools, and that tool requires .RTF input. Ultimately, this macro will allow the user to select a .DOC file, which will be converted to .RTF and passed to this proprietary tool which will alter the RTF file. Once that's done, the macro will convert the updated .RTF into a .DOC file, and overwrite the original .DOC. I can figure out how to do everything except the actual conversion of the files.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Something like this:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oDialog As Office.FileDialog
    Dim strFileName
    Dim oDoc As Document
      Set oDialog = Application.FileDialog(msoFileDialogFilePicker)
      With oDialog
        .AllowMultiSelect = False
        .Title = "Select the file to convert"
        .Filters.Add "Word", "*.doc*"
        .Filters.Add "All", "*.*"
         If .Show Then strFileName = .SelectedItems(1)
         Set oDoc = Documents.Open(strFileName, , , False, , , , , , , , False)
         oDoc.SaveAs2 FileName:="Some File Name.rtf", FileFormat:=wdFormatRTF
          oDoc.Close wdSaveChanges
       End With
    lbl_Exit:
      Set oFD = Nothing: oDoc = Nothing
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Glorious. Thank you!

Posting Permissions

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