Can We Use MS Graph API in MS Project VBA

TJTalha 1 Reputation point


i have just created a simple app in 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

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

i have used the code mention in the below link


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

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

3 answers

Sort by: Most helpful
  1. Deva-MSFT 2,256 Reputation points Microsoft Employee
    • 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

    @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 = ""  
        xml.Open "GET", urltoken, False  
        xml.send ("client_id=XXXXXXXXXXXXXX&scope= 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  
             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.

  3. Jose Roberto Oliveira 0 Reputation points

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

    0 comments No comments