我試著改動程式碼但沒有任何反應
Sub searchIT(rng As Range)
Dim XH As Object
Dim shpRm As Shape
Columns("B:B").Select
With Selection.Font
.Name = "Arial Unicode MS"
.Size = 12
End With
Range("a1").Select
Dim iurl, iurl2 As String
'清除已有的解釋及音標
iurl = "http://www.oxfordlearnersdictionaries.com/definition/english/?q="
iurl2 = "http://dict.tw/index.pl?query="
For Each rng In ActiveSheet.Range("a1", ActiveSheet.Range("a50").End(xlUp))
rng.Select
If rng.Value <> "" Then
rng.Select
Set XH = CreateObject("Microsoft.XMLHTTP")
With XH
.Open "get", iurl & rng, False
.send
' On Error Resume Next
'從Yahoo字典摘取第一組中文翻譯
If InStr(.responseText, "><h4>1.") > 0 Then rng.Offset(0, 2) = Trim(Split(Split(.responseText, "><h4>1.")(1), "<")(0))
'摘取KK音標
If InStr(.responseText, ">KK[") > 0 Then rng.Offset(0, 1) = "[" & Split(Split(.responseText, ">KK[")(1), "]")(0) & "]"
.Open "get", iurl2 & rng, False
.send
'從DICT.TW 英漢字典擷取字義
If InStr(.responseText, "</span><br /> ") > 0 Then rng.Offset(0, 3) = Split(Split(.responseText, "</span><br /> ")(1), "<")(0)
End With
End If
Next
End Sub作者: stillfish00 時間: 2015-12-10 15:36
(A) 模式係將函示分為兩個函式處裡不同內容:
A-1. Function searchIT(rng As Range)
從 Yahoo 字典摘取第一組 KK 音標、中文翻譯
A-2. Function dictionary_oxford(word As String)
抓取對應之牛津英辭解釋。
(B) 模式係將函示合而為一,以一個函式處裡 A-1 以及 A-2
不同作業內容:
B. Function searchITA(rng As Range)
擇一執行,可依你個人喜好選擇,A 案係依處裡不同內容,而
有其各自的函式包裝,事後可依其它實務需求易於組合包裝;
B 案係為整合式函式。)