VJ4Testing
VJ4Testing

Reputation: 101

How to save used range as html file?

I have a requirement where I need to save only result sheet as html file so that I can attach it and email using vb scripting. I tried the following code but it changes even the name of the spreadsheet to the target html file name. Also, I need to save just one sheet as html and not all the sheets.

ThisWorkbook.Sheets("Result").SaveAs "C:\Work\Result.html", xlHtml

Upvotes: 0

Views: 705

Answers (1)

Tim Williams
Tim Williams

Reputation: 166196

If you record a macro while exporting just the selected range to HTML you'll get something like this, which you can then modify to suit your needs:

Range("B3:C23").Select
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
    "C:\Book1.htm" _
    , "Sheet2", "$B$3:$C$23", xlHtmlStatic, "Book1_7762", "Export")
    .Publish (True)
    .AutoRepublish = False
End With

Upvotes: 1

Related Questions