Can We Use MS Graph API in MS Project VBA

TJTalha 1 Reputation point
2021-01-15T07:17:23.087+00:00

Hello.,

i have just created a simple app in vb.net to create planner Task using MS Graph API and Its working fine.

i am thing now its very easy to me ,if i use the above code in MS Project VBA instead of VB.net.

can anyone help me, how to use MS Graph API in MS Project VBA.

i have used the code mention in the below link

how-to-call-microsoft-graph-api-using-vba

but i am getting error in below coding:
GetToken = doc.getElementsByName("access_token")(0).Value

error detail is:
Run time error '91'
Object variable or With Block variable not set

Please help me to resolve this
TJTalha

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,447 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Deva-MSFT 2,261 Reputation points Microsoft Employee
    2021-01-15T19:00:51.877+00:00
    • Make sure that the object that you're trying to use is not properly set
    • Validate its related references are added properly in VBA references
    • Implement VBA exception handling to get more detailed info
    1 person found this answer helpful.

  2. TJTalha 1 Reputation point
    2021-01-18T10:19:20.397+00:00

    @Deva-MSFT thanks for your replay.

    i have used below code to get cleint secret.

    Function GetToken()  
        Dim xml As New MSXML2.XMLHTTP60  
        Dim doc As MSHTML.HTMLDocument  
        Dim urltoken As String  
      
        'copy paste the URL you see when calling Microsoft Graph Explorer and add prompt + domain_hint parameters  
        urltoken = "https://login.microsoftonline.com/XXXXXXXXXXXXXX/oauth2/v2.0/token"  
      
        xml.Open "GET", urltoken, False  
      
        xml.send ("client_id=XXXXXXXXXXXXXX&scope=https://graph.microsoft.com/.default&grant_type=client_credentials&client_secret=(cleint secret}")  
      
        If xml.readyState = 4 And xml.Status = 200 Then  
            Set doc = New MSHTML.HTMLDocument  
            doc.Body.innerHTML = xml.responseText  
      
            GetToken = doc.getElementsByName("access_token")(0).Value  
      
            sSuccess = True  
        Else  
             MsgBox "Error" & vbNewLine & "Ready state: " & xml.readyState & _  
             vbNewLine & "HTTP request status: " & xml.Status  
             sSuccess = False  
        End If  
      
        Set xml = Nothing  
    End Function  
    

    also i have added reference "MSXML v6.0" .

    Is any think needed to change please help me.
    TJTalha


  3. Jose Roberto Oliveira 0 Reputation points
    2023-04-04T00:30:07+00:00

    Any updates on this? I'm struggling with the same error. :(

    0 comments No comments