|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Private Function GetFileText(filePath As String, Optional charSet = "utf-8")
- Dim stream As Object
-
- Set stream = CreateObject("adodb.stream")
-
- With stream
- .charSet = charSet
- .Type = 2
- .Open
- .LoadFromFile filePath
- GetFileText = .readText
-
- End With
- Set stream = Nothing
-
- End Function
- Sub GetHTML()
- Dim folderPath$, filePath$
-
- folderPath = GetFolderPath
-
- If folderPath = "" Then Exit Sub
-
- filePath = Dir(folderPath & "\*.htm*")
-
- Dim dom As Object
-
- Dim title$, body
-
- While filePath <> ""
-
- Set dom = CreateObject("htmlfile")
-
- dom.write GetFileText(folderPath & "" & filePath)
-
- title = dom.getElementsByTagName("span").Item(0).ChildNodes(1).innerText
-
- body = "<table>" & dom.getElementsByTagName("div").Item(2).innerHTML & "</table>"
-
- dom.parentWindow.clipboardData.setData "text", body
-
- Set dom = Nothing
-
- With Worksheets.Add
- .Name = title
- .Activate
- .PasteSpecial Format:="Unicode 文本", Link:=False, DisplayAsIcon:=False
- End With
-
- filePath = Dir()
-
- Wend
- End Sub
- Private Function GetFolderPath()
- Dim FileDialog
-
- Set FileDialog = Application.FileDialog(msoFileDialogFolderPicker)
-
- FileDialog.title = "请选择数据文件夹"
-
- FileDialog.Show
-
- If FileDialog.SelectedItems.Count = 0 Then
-
- Set FileDialog = Nothing
-
- GetFolderPath = ""
-
- Exit Function
- End If
-
- GetFolderPath = FileDialog.SelectedItems(1)
-
- Set FileDialog = Nothing
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|