1 回答
TA贡献1788条经验 获得超4个赞
对于非连续范围,您可能必须将其作为连续范围复制到临时工作表并将其导出
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Const folder = "C:\tmp\"
Const xlFile = "test1.xlsx"
Const htmlfile = "export.html"
Dim xls As New Excel.Application
Dim wb As Workbook
Dim ws As Worksheet, wsHtml As Worksheet
wb = xls.Workbooks.Open(folder & xlFile, False, True) ' no link update , radonly
ws = wb.Worksheets("Sheet3")
' create temp sheet, copy range to it, export and then delete it
wsHtml = wb.Sheets.Add()
ws.Range("A:A,C:C").Copy(wsHtml.Range("A1"))
wsHtml.PageSetup.PrintArea = wsHtml.Columns("A:B").Address
wsHtml.SaveAs(Filename:=folder & htmlfile, FileFormat:=44) ' html
xls.DisplayAlerts = False
wsHtml.Delete()
xls.DisplayAlerts = True
wb.Close(False)
xls.Quit()
MsgBox("Exported to " & folder & htmlfile)
End Sub
- 1 回答
- 0 关注
- 133 浏览
添加回答
举报