RTF (Rich Text Format)
A word processing system which can be used to store text, images, tables etc. with certain limitation as compare to Microsoft Word Document. Let’s write code to convert RTF files to Word Document using VBA.
Code example
Sub ConvertRtfToDocxCodeExample() With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Select folder..." .Show If .SelectedItems.Count = 0 Then Exit Sub Else myFolder = .SelectedItems.Item(1) End If End With myWildCard = InputBox(prompt:="Enter wild card...") myDocs = Dir(myFolder & "\" & myWildCard) While myDocs <> "" Documents.Open FileName:=myFolder & "\" & myDocs, ConfirmConversions:=False ActiveDocument.SaveAs2 FileName:=myFolder & "\" & Left(myDocs, Len(myDocs) - 4) & ".docx", _ FileFormat:=wdFormatDocumentDefault, _ CompatibilityMode:=wdCurrent ActiveDocument.Close SaveChanges:=False myDocs = Dir() Wend MsgBox "Operation Complete" End Sub
The above code can be attached to any interface and make it working. The wildcard input should go as “*.rtf“
Next >> Drop Cap in Microsoft Word using VBA code