excel / VBA:检测IE内部文本字体

时间:2018-11-27 05:33:34

标签: excel vba innertext

我需要检测所选内部文本的字体是否为粗体。我只需要一个有效的语法。请帮助:(

现在我正在使用它,但是它不起作用:

<table>
  <col>
  <colgroup span="2"></colgroup>
  <colgroup span="2"></colgroup>
  <tr>
    <td rowspan="2"></td>
    <th colspan="2" scope="colgroup">Mars</th>
    <th colspan="2" scope="colgroup">Venus</th>
  </tr>
  <tr>
    <th scope="col">Produced</th>
    <th scope="col">Sold</th>
    <th scope="col">Produced</th>
    <th scope="col">Sold</th>
  </tr>
  <tr>
    <th scope="row">Teddy Bears</th>
    <td>50,000</td>
    <td>30,000</td>
    <td>100,000</td>
    <td>80,000</td>
  </tr>
  <tr>
    <th scope="row">Board Games</th>
    <td>10,000</td>
    <td>5,000</td>
    <td>12,000</td>
    <td>9,000</td>
  </tr>
</table>

编辑:

我有一个自动化程序,可以在运营商网站上收集信息。我的代码可以正常工作并获取所有必要的数据。现在,我正在下一步,仅在网站上获取粗体字。经过数小时的搜索,我尝试了许多语法,但是它们都不起作用。我只需要使用这条线,这样我就可以继续下一步了。 :)

If elemCollection(t).Rows(r).Cells(c).fontWeight = 400 Then '<-- or "bold"
    MsgBox 1
End If

这是我的代码。

If elemCollection(t).Rows(r).Cells(c).style.fontWeight = 400 Then '<-- or 
    "bold"
    'code here
End If

link

Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub extractTablesData()
Dim IE As Object, obj As Object
Dim r As Integer, c As Integer, t As Integer
Dim elemCollection, elemClass As Object
Dim wb, twb As Workbook
Dim idStr As String
Dim ctr, RowCtr As Long

Set wb = ActiveWorkbook

DoEvents
For x = 2 To Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
If Sheet2.Range("B" & x).Value <> "" Then
idStr = Sheet2.Range("B" & x).Value
Set IE = CreateObject("InternetExplorer.Application")
Sheet2.Range("A" & x & ":b" & x).Copy
Sheet3.Range("A" & Sheet3.Cells(Rows.Count, 1).End(xlUp).Row + 1).PasteSpecial xlPasteValues
With IE
.Visible = True:
'added sample for your reference of the website
.navigate ("click the link"

0 个答案:

没有答案