简体   繁体   English

如何将EXCEL 2010中的选定单元格导出为HTML。 每次导出的像元范围可能不同吗?

[英]How do I export selected cells in EXCEL 2010 as HTML. Cell range may be different on each export?

I am looking to export selected cells in EXCEL 2010, to an HTML file. 我想将EXCEL 2010中的选定单元格导出到HTML文件。

The selected cells will change before each export so the cell range can't be hard coded into the VBA. 选定的单元将在每次导出之前更改,因此无法将单元范围硬编码到VBA中。 The Macro I have recorded for one export produced this 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

I have not been able to find a way of changing: "A1:AI26" to match the cells selected. 我还没有找到一种更改方式:“ A1:AI26”以匹配所选的单元格。

I hope someone can help, Thank you. 希望有人能帮助您,谢谢。

Without further optimization: 无需进一步优化:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM