我希望将EXCEL 2010中的选定单元格导出为HTML文件。
所选单元格将在每次导出之前更改,因此单元格范围无法硬编码到VBA中。 我为一次出口录制的宏制作了这个VBA:
Sub ExportHTML()
Range("A1").Select '
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
"Q:\Library Resource Centre\AR\AR Project 2015-16\Admin.htm", "Export", _
"A1:AI26", xlHtmlStatic, "Admin_20257", "")
.Publish (True)
.AutoRepublish = False
End With
End Sub
我无法找到改变的方法:“A1:AI26”以匹配所选的细胞。
我希望有人能提供帮助,谢谢。
答案 0 :(得分:0)
没有进一步优化:
Sub ExportHTML()
dim wks as worksheet
dim strRng as String
set wks=Thisworkbook.Worksheets(1) 'Assuming you are working with the 1st Worksheet. Adjust insex number if needed.
strRng = wks.Range("A1", ActiveCell.SpecialCells(xlLastCell)).address
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
"Q:\Library Resource Centre\AR\AR Project 2015-16\Admin.htm", "Export", _
wks.Name & "!" & strRng, xlHtmlStatic, "Admin_20257", "")
.Publish (True)
.AutoRepublish = False
End With
End Sub