Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-21-2022, 03:37 AM
firm firm is offline How do I covert HTML documents to word using Macro? Windows 10 How do I covert HTML documents to word using Macro? Office 2016
Novice
How do I covert HTML documents to word using Macro?
 
Join Date: Feb 2022
Posts: 2
firm is on a distinguished road
Default How do I covert HTML documents to word using Macro?

I am new to vba and I have googled searched how to convert html document to word using macro without success. I have the html files in a folder and would like the vba to lop through the html files and convert them to word.
Reply With Quote
  #2  
Old 02-22-2022, 07:11 PM
Souriane Souriane is offline How do I covert HTML documents to word using Macro? Windows 10 How do I covert HTML documents to word using Macro? Office 2019
Advanced Beginner
 
Join Date: Feb 2017
Location: Quebec, Canada
Posts: 82
Souriane is on a distinguished road
Default

Hi!

Try this one

Code:
Sub ConvertirHtml_Docx()

Dim objWordApplication As New Word.Application
  Dim objWordDocument As Word.Document
  Dim strFile As String
  Dim strFolder As String

'Change the folder name here
  strFolder = "c:\temp\myfolder\"
  strFile = Dir(strFolder & "*.html", vbNormal)
  
  While strFile <> ""
    With objWordApplication
      Set objWordDocument = .Documents.Open(FileName:=strFolder & strFile, _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:="")
          
      With objWordDocument
        .SaveAs2 FileName:=strFolder & Replace(strFile, "html", "docx"), FileFormat:=wdFormatXMLDocument, CompatibilityMode:=15
        .Close
      End With
    End With
    strFile = Dir()
  Wend

  Set objWordDocument = Nothing
  Set objWordApplication = Nothing

End Sub
Souriane
Reply With Quote
Reply

Tags
html conversion, macro automatic, word 16

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Symbol characters when saving Word documents as HTML amos Word 3 09-30-2023 02:00 PM
How do I covert HTML documents to word using Macro? Trying to combine Word documents using Excel macro rotunda Word VBA 6 06-14-2021 10:42 AM
How do I covert HTML documents to word using Macro? Covert PDF to Word .doc? mobileone Word 3 02-01-2017 10:51 AM
covert excel to words zenholy Excel 0 07-17-2010 07:55 PM
Can you actually write HTML and CSS in a word document and send it as an html page jackaroo Word 0 07-12-2010 07:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft