Excel export cell range to HTML via Macro

griffj

Board Regular
Joined
May 29, 2015
Messages
56
Hi

I have the following macro which exports my sheet (Page1) as an HMTL file and it works well, except it exports the entire page. I was wondering if it could be modified to export only a selection of cells on the page? such as A1:CN106?

VBA Code:
Sub HTML_File()

    With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, "C:\Exports\Page1.htm", "Page1", , xlHtmlStatic, , "")
        .Publish (False)
        .AutoRepublish = True
    End With
    
End Sub

Thanks to L42's answer on Stackoverflow for the macro

Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I have never used PublishObjects and know absolutely nothing about it, but from this example from Excel VBA help, it appears that you can do a modification to export a range. Hope this helps.

PublishObjects.Add Method


Example

This example saves the range D5:D9 on the First Quarter worksheet in the active workbook to a Web page
called Stockreport.htm.


Visual Basic for Applications
With ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceRange, _
Filename:="\\Server\Stockreport.htm", Sheet:="First Quarter", Source:="$G$3:$H$6", _
HtmlType:=xlHtmlStatic, DivID:="Book1_4170")
.Publish (True)
.AutoRepublish = False
End With
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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