Excel VBA PUT Json

烂漫一生 提交于 2020-01-15 12:21:44

问题


How can I make this work now? I'm trying to get the value from Column Y (rng1) and also the value from Column Z (rng2)

    Dim xhr As Object, thisRequest As String, rng1 As Range, rng2 As Range

Set xhr = CreateObject("Microsoft.XMLHTTP")

With ThisWorkbook.Worksheets("Fulcrum Upload")
    For Each rng1 In .Range("Y3:Y" & .Cells(.Rows.Count, "Y").End(xlUp).Row).SpecialCells(xlVisible)
    For Each rng2 In .Range("Z3:Z" & .Cells(.Rows.Count, "Z").End(xlUp).Row).SpecialCells(xlVisible)
        If Not IsEmpty(rng1) Then
            With xhr
                .Open "PUT", "https://api.fulcrumapp.com/api/v2/records/" + rng2 + ".json", False
                .setRequestHeader "Accept", "application/json"
                .setRequestHeader "Content-type", "application/json"
                .setRequestHeader "X-ApiToken", "11111111"
                .send rng1.value
            End With
        End If
    Next
End With

回答1:


I think you want to use offset to grab the adjacent value and thereby only need one loop. And use & to concantenate string.

With ThisWorkbook.Worksheets("Fulcrum Upload")
    For Each rng1 In .Range("Y3:Y" & .Cells(.Rows.Count, "Y").End(xlUp).Row).SpecialCells(xlVisible)
            If Not IsEmpty(rng1) Then
                With xhr
                    .Open "PUT", "https://api.fulcrumapp.com/api/v2/records/" & rng1.Offset(, 1).Value & ".json", False
                    .setRequestHeader "Accept", "application/json"
                    .setRequestHeader "Content-type", "application/json"
                    .setRequestHeader "X-ApiToken", "11111111"
                    .send rng1.Value
                End With
            End If
        Next
    End With
End Sub


来源:https://stackoverflow.com/questions/52063350/excel-vba-put-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!