VBA 一直是我處理這種臨時性小需求的好夥伴,可惜久久用一次,語法常常忘記,每次 Google,還不如在自己的 Blog 翻
HTTP Request 可以分成 POST 和 GET 兩種方式。我不是寫 Web Application 出身的,背不住 POST 和 GET 差在哪裡,我只知道 VBA 採 GET 方式處理,程式比較直覺與簡單,紀錄一下我的小程式碼
Sub 按鈕1_Click()
Dim result As String
Dim myURL As String
Dim winHttpReq As Object
Dim i As Integer
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
For i = 6 To 194
If ThisWorkbook.Sheets(1).Cells(i, 4).Value = "" Then
myURL = ""
result = ""
myURL = "http://sample_server/sample_ap/sample?p1=abcde&p2=" & ThisWorkbook.Sheets(1).Cells(i, 2) & "&p3=" & ThisWorkbook.Sheets(1).Cells(i, 3)
winHttpReq.Open "GET", myURL, False
winHttpReq.Send
result = winHttpReq.responseText
ThisWorkbook.Sheets(1).Cells(i, 4).Value = result
End If
Next i
End Sub
沒有留言:
張貼留言