我正在嘗試編寫一個(gè) VBA 腳本,它通過一列單元格和一個(gè)單元格,在 html<u></u>標(biāo)簽和兩個(gè)標(biāo)簽之間的文本下劃線,然后從文本中刪除這些標(biāo)簽。單元格內(nèi)部可能有多個(gè)標(biāo)簽,它們旁邊有其他文本,或者根本沒有標(biāo)簽。到目前為止,我已經(jīng)能夠讓腳本在標(biāo)簽之間加下劃線,但是當(dāng)我嘗試刪除它們時(shí),沒有任何效果(有時(shí)什么都沒有改變,有時(shí)標(biāo)簽帶有下劃線等)。為簡(jiǎn)潔起見,我省略了輸入/輸出示例,并希望我的代碼存在明顯的問題,但可應(yīng)要求提供。嘗試使用 VBA 解決這個(gè)問題最初源于我無法在 Python 中執(zhí)行此操作,因?yàn)閷?duì)象模型僅與單元格一樣低,而不是單元格的內(nèi)容。任何使用 Python 執(zhí)行此操作的解決方案也將不勝感激!非常感謝你的幫助!如果還有什么我能做的來幫助大家,請(qǐng)告訴我!Sub PleaseUnderline()'Holds the content between the tagsDim s As String'Holds the row number of the active cellDim a As Integer'Holds the location of the beginning of the open tagDim b As Integer'Holds the location of the beginning of the close tagDim e As IntegerDim holder As String 'Select the last cell in column A and make it the active cell Range("A" & ActiveCell.SpecialCells(xlLastCell).Row).Select For a = ActiveCell.Row To 1 Step -1 Range("A" & a).Select holder = Range("A" & a).Value s = "" b = 1 e = 1 Do b = InStr(b, ActiveCell, "<u>") If b = 0 Then Exit Do e = b + 1 e = InStr(e, ActiveCell, "</u>") If e = 0 Then Exit Do Else s = Mid(ActiveCell, b + 3, e - b - 3) End If holder = Replace(holder, "<u>", "", 1, 1) holder = Replace(holder, "</u>", "", 1, 1) Worksheets("Sheet").Range("A" & a).Value = holder ActiveCell.Characters(b, Len(s)).Font.Underline = True b = e + 1 Loop Next aEnd Sub
添加回答
舉報(bào)
0/150
提交
取消