Saturday, March 31, 2018

Macro to convert bulk word file to html filtered file

Macro to convert bulk word file to html filtered file

Sub all_to_htm()
'
' all_to_htm Macro
'
'
 Dim directory As String
    directory = "Z:\mathmuni2\docs\2017-11-30" ' The starting directory
 
    Dim fso, newFile, folder, files
    Set fso = CreateObject("Scripting.FileSystemObject")
  
    Set folder = fso.GetFolder(directory)
    Set files = folder.files
  
    For Each file In files
      
        'MsgBox (file.ParentFolder)

        Dim newName As String
        newName = Replace(file.Name, ".docx", ".htm")
        'newName = Replace(file.path, ".docx", ".htm")
        Dim newPath As String
        newPath = directory + "\html_images\" + newName
      
      
      
        ChangeFileOpenDirectory directory
        Documents.Open FileName:= _
            file.path, _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
      
        ActiveDocument.SaveAs FileName:= _
            newPath, FileFormat:= _
            wdFormatFilteredHTML, LockComments:=False, Password:="", AddToRecentFiles _
            :=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
            :=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
            SaveAsAOCELetter:=False
        ActiveWindow.View.Type = wdWebView
        ActiveDocument.Close
      
    Next
End Sub

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...