We have .htm files we would like to edit with an Excel macro.
Here's what I have so far, which is an attempt to open the file, replace some placeholders inside the HTML body, and then save the file as an HTML file:
Sub SaveCustomerCountHTML()
Dim customerCountHTML As HTMLDocument
Dim customerCount As String
Dim customerPercentage As String
Dim strHTML As String
Set customerCountHTML = CreateObject("O:\00.Department Documents\06.Status Board Updates\Daily Sales\Templates\CUSTOMER COUNT.htm")
strHTML = customerCountHTML.HTMLbody
customerCount = "55"
customerPercentage = "2"
strHTML = Replace(customerCountHTML.HTMLbody, "%CUSTOMERCOUNT%", customerCount)
strHTML = Replace(customerCountHTML.HTMLbody, "%CUSTOMERPERCENTAGE%", customerPercentage)
customerCountHTML.SaveAs Filename:= _
"O:\00.Department Documents\06.Status Board Updates\Daily Sales\Templates\CUSTOMER COUNT2.htm", _
FileFormat:=xlHtml, _
CreateBackup:=False
End Sub
We definitely don't want to open the file in Internet Explorer - we just want to edit the placeholders in the body and re-save to another folder it without seeing what it's doing.
I receive an error message "ActiveX component can't create object" on the "Set customerCountHTML" line. We were also getting an "Object doesn't support this property or method" error for the HTMLBody lines, even though we included the Microsoft HTML Object Library in our references.
Again, the intention/attempt is to simply open the HTML file as an object, replace text in that file, and save the file. All of this without needing to see anything opening or closing. Most of the answers online include Internet Explorer or Outlook in some way, and we simply want to edit the file.