Hi,
My project need to build the new button(s) by row level and let user through the button to trigger the function from EXCEL to API server. For instance, Approve / Reject processes.
I have [2] problems on coding level.
[1] When I change the coding to [OnAction = withReviewProc(nHYPER_APP, i)], the function is work BUT is not trigger by user. The function is auto-run when I call other button/procedure cmdBTEnquiry_Click() to query the data from API.
[2] When I use coding [OnAction = "btn"], the auto-run function is stopped, good. But I have no the idea how to trigger the function [withReviewProc] via on generated button
** Source : Link **
Here is my code.
Remark : [nHYPER_APP] is generate by dynamic coding. Each row(s)/button(s) should be pass the unify id to API server and let API server to update the specified dataset.
Here is the function of withReviewProc
My project need to build the new button(s) by row level and let user through the button to trigger the function from EXCEL to API server. For instance, Approve / Reject processes.
I have [2] problems on coding level.
[1] When I change the coding to [OnAction = withReviewProc(nHYPER_APP, i)], the function is work BUT is not trigger by user. The function is auto-run when I call other button/procedure cmdBTEnquiry_Click() to query the data from API.
[2] When I use coding [OnAction = "btn"], the auto-run function is stopped, good. But I have no the idea how to trigger the function [withReviewProc] via on generated button
** Source : Link **
Here is my code.
Rich (BB code):
Private Sub cmdBTEnquiry_Click()
:
For Each item In JSONa("entry_list")
:
i = 7
nHYPER_APP = "http://api.xyz.com/api/rest.php?method=setentries&input_type=JSON&response_type=JSON&rest_data={"module":"V3295","name_value_list":[{"id":"9eb47658zyxxxxx","review":"Approve"}]}"
'Create button - Start
Dim btn As Button
Application.ScreenUpdating = False
'ActiveSheet.Buttons.Delete
Dim t As Range
Set t = ActiveSheet.Range(Cells(i, 1), Cells(i, 1))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
'.OnAction = "btn"
.OnAction = withReviewProc(nHYPER_APP, i)
.Caption = "Approve"
'.Caption = "Btn " & i
.Name = "Btn" & i
End With
Application.ScreenUpdating = True
'Create button - End
i = i + 1
:
:
Next
:
End Sub
Here is the function of withReviewProc
Code:
Function withReviewProc(ByVal myurl As String, ByVal nopos As Integer)
Dim xmlhttp01 As New MSXML2.XMLHTTP60
xmlhttp01.Open "post", myurl, False
xmlhttp01.send
nRLT02 = xmlhttp01.responseText
Set JSONe = JsonConverter.ParseJson(nRLT02)
def = JSONe("ids")(1)
If Len(def) > 0 Then
Worksheets("Approval_WB").Cells(nopos, "N").Value = "Updated:" & def
Else
Worksheets("Approval_WB").Cells(nopos, "N").Value = "Not match"
End If
End Function
Attachments
Last edited by a moderator: