Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

Macro to export runs



I have been doing some reports about test execution and I’m dependent of TestRail exports about the runs in some Drop or Milestone. I got something like this in my excel report:

I’m doing this manually, I’m going to TestRail and export and then finally paste it in my excel.

Is there any way of doing this with an excel macro?

Best regards


Hi João,

Thanks for your posting. You can use the CSV/Excel exports and should be able to open this directly in Excel. You can create export by clicking on the icon with the arrow pointing to the right (next to the printer icon in the blue toolbar). Just include the columns you need in the export. The relevant columns would be Title, Defects, Run and Status and you can select them on the Export to CSV dialog:



Hi Tobias,

I know that and I’m actually doing that. But I want a macro to execute that for me and to have no need to open TestRail to export.

Can you help with this request?



Hi João,

Thanks for your reply. If you want to automate this, I would recommend looking into the API instead and this would be the most flexible option:

You can pull the same data as with the CSV exports by using the get_tests and/or get_results_for_run API methods:




I’m a little bit newbie at API creation. At this moment I have something like this in my macro (with all the login thing created in the macro):

Public Function getResultsForRun(run_ As Object)

Dim getResultsAsRun As New MSXML2.XMLHTTP60
Dim url As String
Dim project As Object
Dim run As Object
Dim sFields As String
sFields = Worksheets(“Login”).Cells(11, 3)
Dim run_id As String

For i = 1 To run_.Count

    run_id = run_(i)("id")

    url = "" & run_id

    With getResultsAsRun
    .Open "Get", url, False
    .setRequestHeader "Content-Type", "application/json"
    .setRequestHeader "Authorization", "Basic " & UserPassBase64
   'Worksheets("Login").Cells(i + 1, 1).value = .responseText
   Worksheets("Login").Range("A32").value = .responseText
    Dim lib As New JSONLib
    Dim json As Object

    Set runs = lib.parse("" & .responseText & "")

    If .Status = "401" Then
        MsgBox "Not authorized or invalid username/password"
    End If
End With


getResultsForRun run

End Function

But when I press the macro button I dont get any results…What am I doing wrong? Can you help?



Hi João,

Thanks for your reply! It would be difficult to troubleshoot this type of custom code as we haven’t been able to test such implementations and wouldn’t be able to help much with this unfortunately. If you have another team member with this type of programming experience it might be best to check if they have some insight into this, or perhaps posting your question on programming Q&A websites such as Stack Overflow might also be a better idea. Sorry we couldn’t be of more help!