|
楼主 |
发表于 2022-6-17 16:16
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- '使用对象转换将表格区域转换为html
- Function tableConversionHTML2(rng As Range)
- Dim wb As Workbook, wsh As Object, path As String, fs As Object, adoStream As Object
- '获取传入单元格的工作簿
- Set wb = rng.Parent.Parent
- '创建wscript.shell对象
- Set wsh = CreateObject("wscript.shell")
- '创建fileSystemObject对象
- Set fs = CreateObject("Scripting.FileSystemObject")
- '创建ado对象
- Set adoStream = CreateObject("adodb.stream")
- 获取临时文件夹 , 并连接指定名称
- path = wsh.SpecialFolders("Templates") & "\temp.htm"
- '将区域导出为htm文件
-
- With wb.PublishObjects.Add(xlSourceRange, path, rng.Parent.name, rng.Address, xlHtmlStatic, "", "")
- .Publish (True)
- .AutoRepublish = True
- End With
- '获取导出文件文本
- With adoStream
- .Type = 2
- .Charset = "GBK"
- .Open
- .LoadFromFile path
- '函数返回文本
- tableConversionHTML2 = .readText
- .Close
- End With
- '删除文件
- fs.deletefile path, True
- '释放对象
- Set wb = Nothing
- Set wsh = Nothing
- Set fs = Nothing
- Set adoStream = Nothing
- End Function
复制代码 新方法 通过PublishObjects.Add实现
|
评分
-
3
查看全部评分
-
|