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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,223,631
Messages
6,173,465
Members
452,516
Latest member
archcalx

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