D. G. Schneider International Lions Club Volunteer Project

Automated file conversion using a Word Macro VBA

To be competitive, it is necessary in our days to automate the maximum of repetitive tasks. This simple Word macro will open every RTF file located in a folder and save each file as HTML format. The macro will keep the name of the open RTF file and save it keeping the same name but with a HTML xtension:

Sub Macro1()
' Macro1 Macro
' Macro recorded 8/4/2005 by Dominque Schneider

Dim File
Dim MyRootName As String

ChangeFileOpenDirectory "C:\dgschnei\Portfolio\Development\dscan_code\HLP2CMH\verbs\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder("C:\dgschnei\Portfolio\Development\dscan_code\HLP2CMH\verbs")

Set F_Files = Folder.Files

If fso.folderexists("C:\dgschnei\Portfolio\Development\dscan_code\HLP2CMH\verbs") = "True" Then

For Each File In F_Files

If LCase(File.Type) = "rich text format" Then

MyRootName = fso.GetBaseName(File.Name)

Documents.Open FileName:=File.Name, ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto, XMLTransform:=""

ActiveDocument.SaveAs FileName:=MyRootName & ".htm", FileFormat:= _
wdFormatFilteredHTML, LockComments:=False, Password:="", AddToRecentFiles _
:=False, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _

ActiveWindow.View.Type = wdWebView

End If


End If

End Sub

For more information on how to create macros, see the on-line help of the text editor software you are using.
Word offers two ways for you to create a macro: the macro recorder and the Visual Basic Editor.
To get sample macros from Microsoft, go to and type "" in the search field.
You can type "Q237356" , "Sample Macros for Word 2000", "Q123606" , "Supplemental Macros for Word 6.0".

About Dominique Gérard Schneider since 1995
Participation on Google on YouTube

Tek-Tips Forums dgschnei
Listed since 1996 ixquick
Community Services

platform sdk dgschnei
About Me

Return Home - Index