Search code examples
vbahttpexcelput

Running script on all columns in excel/VBA


So, I have an HTTP PUT request that I need to run on a large amount of data. (50,000+ cells)

All of this is contained in two rows, and about 25,000 columns. First row is the HTTP URL to PUT to, the second is data that will be part of a larger string as the request.

Assuming the first two columns of my sheet are as follows, where the cells are separated via comma

Location1, Sample Data 1
Location2, Sample Data 2

I will be sending a PUT request to domain.com/API/Location1 containing the string "data=Sample Data 1" where "domain.com/API/" Is a constant and "data=" is also a constant.

Not knowing enough about excel, I just created a button to call my code. I am still figuring out how to insert cell data into this code.

Private Sub CommandButton1_Click()

URL = "https://domain.com/api/Location1" 
DATA = "here_is_a_long_string_specifying_the_value_to_modify=Sample Data 1"
   Set HTTP = CreateObject("Microsoft.XMLHTTP")
   HTTP.Open "PUT", URL, False
   HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   HTTP.send REQUEST

End Sub

Ultimately I would like it to do something like URL = ""(1,x)

Then proceed through the list so (1,1) then 1,2 and 1,3, etc..

I am unsure where to direct my searches at this point


Solution

  • So, I got my script working

    x=0
    While x < 25000
    x = (x + 1)
    URL = "https://domain.com/api/" Sheet1.Cells(x, 1)
    DATA = "string_of_data=" Sheet1.Cells(x, 1)
       set HTTP = CreateObject("Microsoft.XMLHTTP")
       HTTP.Open "PUT", URL, False, "Login", "Password"
       HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
       HTTP.send DATA
    wend