Save a single worksheet as html and set a specific html code for the exported html

kinny2009

New Member
Joined
Jul 7, 2016
Messages
18
The below code was typed for export the worksheet into a html. However, I would like to set a specific html code for it. Is it possible to do so in VBA?

Many thanks
Kinny

Code:
Private Sub CommandButton2_Click()
    Dim str, myfolder, myfile, fName As String
    str = "Do you want to save these sheets to a single html file?" & Chr(10)
    answer = MsgBox(str, vbYesNo, "Continue with save?")
    If answer = vbNo Then Exit Sub
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
    myfolder = .SelectedItems(1) & "\"
    End With
    myfile = InputBox("Enter filename", "Save as..")
    If myfile = "" Then Exit Sub
    ThisWorkbook.Sheets("Risk").range("A1:BF113").Select
    With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
        Filename:=myfolder & myfile & ".htm", Sheet:="Risk", Source:="A1:BF113", _
        HtmlType:=xlHtmlStatic)
        .Publish (True)
        .AutoRepublish = False
    End With
End Sub
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
excel tend to generate html files with lots of chaotic html code which does not support commom browsers well. i would rather to write the html code by myself
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top