Log in

View Full Version : [SOLVED:] Select a file, export it to RTF



WhiteLieprod
05-12-2017, 10:14 AM
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.

gmaxey
05-12-2017, 04:17 PM
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

WhiteLieprod
05-15-2017, 07:09 AM
Glorious. Thank you!