2014-10-10 57 views
0

我有列,說列A包含1500行,每個都有一個字符串(十六進制編碼)。我需要的是連接到特定的網站搜索粘貼字符串,按解碼,複製結果並粘貼回B列。Excel VBA宏連接到一個特定的網頁 - 搜索和檢索數據

任何幫助都會有很大的幫助。我剛來這地方。

實施例:

字符串在柱A:5468616e6b732061206c6f7420696e20616476616e6365

網站中搜索:從Excel細胞http://encodertool.com/hexadecimal

  1. 複製並在標籤粘貼(標題下):輸入十六進制CONTENT TO DECODE
  2. 然後點擊DECODE
  3. 然後從DECODING RESULT複製
  4. 最後在我的Excel表格中粘貼回ColumnB。

期待您的回答。

非常感謝。

回答

1

你在做這個練習來自動化瀏覽器嗎?好像你可以更輕鬆地在VBA

直接做

來源:http://bytes.com/topic/access/answers/874752-convert-hex-string

Sub tester() 
    Debug.Print fConvertHexToString(_ 
      "5468616e6b732061206c6f7420696e20616476616e6365") 
End Sub 



Public Function fConvertHexToString(strHexString As String) As String 
Dim intLenOfString As Integer 
Dim intCounter As Integer 
Dim strBuild As String 

'Hex String must have a valid length, and it must be an even length 
If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function 

intLenOfString = Len(strHexString) 

For intCounter = 1 To Len(strHexString) 
    If intCounter Mod 2 <> 0 Then  'need Hex pairs 
    'Retrieve the Value of the Hex Pair, then Convert to a Character, 
    'then Append to a Base String 
    strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2))) 
    End If 
Next 
fConvertHexToString = strBuild 
End Function 
+0

@ user3752399:哇!正如Tim所建議的那樣,如果它不適合訪問該網站,則可以選擇上述答案。 +1爲轉換 – Sriram 2014-10-12 10:38:53

+0

哇:)非常感謝 – user3752399 2014-10-28 11:21:08

0

就是這樣。我剛剛運行模擬測試,它的工作原理。試一試。您可以根據需要修改代碼。這是一個明碼。代碼也可以增強。但是,這確實你問什麼

 Dim ie As InternetExplorer 
     Dim doc As HTMLDocument 

     Sub start() 

     Dim ran As Range 
     Dim cel As Excel.Range 

     Set ran = Worksheets("Sheet1").Range("A1:A4") 'Change Your input range here 

      For Each cel In ran 
       If cel.Value <> Empty Then 
        Set ie = New InternetExplorerMedium 'open iE 
        ie.navigate ("http://encodertool.com/hexadecimal") 'Navigate to IE 
        ie.Visible = True 
         'Wait untill IE is loaded 
         Do 
         ' Wait till the Browser is loaded 
         Loop Until ie.readyState = READYSTATE_COMPLETE 
        Set doc = ie.document 
        doc.getElementById("input_4").innerText = cel.Value ' Enter input value 
        test ' Click button 
        cel.Offset(0, 1).Value = doc.getElementById("output_4").innerText ' save Output value 
       End If 
       ie.Quit 
       Next cel 

      End Sub 


    'Click the Decode button 
    Sub test() 

      Set cl_button= doc.getElementsByTagName("a") 

      For Each one In cl_button 
      If one.getAttribute("onclick") = "ajaxfct('fcts.php','4')" Then 
      one.Click 
      Exit For 
      End If 
      Next one 

    End Sub 

運行代碼之前,添加引用HTML對象庫&互聯網的控制。還要更改輸入的範圍。我已將它設置爲A1:A4。改變它什麼。確保範圍內沒有空白單元格。此外,如果您不希望瀏覽器顯示集

ie.visible = false 

這是一種方法。有很多簡單而有效的方法可以做到這一點

+0

非常感謝斯利拉姆 - 讓我試試看,並取回你。歡呼聲 – user3752399 2014-10-10 12:15:42