How to Send Excel Automation Result to Telegram Using UiPath?

What I’m Trying to Do

I’m working on an automation project using UiPath where I generate a daily report in Excel using VBA. Instead of sending the result via email, I want to send it directly to Telegram using a bot.

What I Have So Far

  • I have already created a Telegram bot and retrieved the bot token.
  • I also got the chat ID (from a group) and tested sending messages manually using the Telegram API.
  • I successfully generated the Excel report using VBA, and I’m calling it from UiPath using the ‘Invoke VBA’ activity.
  • I want to send the Excel report content (either as text or as a file) to Telegram from UiPath automatically.

What I Need Help With

  • What is the best way to send a message or file (Excel) to Telegram from UiPath?
  • Should I use HTTP Request activity, or is there a better approach?
  • Are there any samples or packages available for Telegram integration in UiPath?

Additional Info

  • I’m using UiPath Studio version 2023.x
  • Telegram message sending already works when I test it with browser and bot API.
  • I just want to fully automate the process from UiPath.

The Problem

When I run the automation in UiPath, I get the following error:

“Trust Access to the VBA project object model must be enabled from Excel…”

I have already checked the setting:
File > Options > Trust Center > Trust Center Settings > Macro Settings > :white_check_mark: Trust access to the VBA project object model
…but I still get the same error.

My Question

Has anyone else experienced this issue when running a VBA macro from UiPath? Is there any workaround or something I might be missing?

Thank you in advance!

@nashwasabila11,

Http request is the best approach.

Regarding this

Refer this solution.

@nashwasabila11

  1. As of now if you dont want to use 3rd party developed activities then http request would be the option..else on marketplace there is a component Telegram Activities - RPA Component | UiPath Marketplace | Overview
  2. Coming to excel issue..when running unattended the settings are to be made on the target machine also if the file is being downloaded then also you might see because there might be file level settings..try saving the vba file outside the file and as .txt instead of vba and check..sometimes the vba file might be the issue so try to recreate a new file

Cheers

Hi, thank you for your reply!

Just to give a bit of context: my automation takes data from three different Excel files, combines them into a single workbook with multiple sheets, and then summarizes the key information into a final sheet called “SummaryReport”. After that, I use VBA through the “Invoke VBA” activity to send the summary table via Telegram.

I already used a separate .txt file for the VBA code in the Invoke VBA activity, but I’m still getting the same error regarding “Trust access to the VBA project object model” even though I’ve already enabled the option in Excel settings.

Do you think there’s something wrong with my code, or could there be another setting that I’m missing?

Here’s the VBA code I’m using:
Sub GenerateAllReports()
’ Step 1: Proses untuk membuat Top5Client dan Top5SID
Call CopyAndSortTop5Sheets

' Step 2: Buat summary report berdasarkan Top5Client dan Top5SID
Call CreateSummaryReport

' Step 3: Kirim laporan ke Telegram
Call SendTelegramReport

End Sub

Sub SendTelegramReport()
Dim http As Object
Dim URL As String
Const botToken As String = “YOUR_BOT_TOKEN” ’ Replace with your bot token
Const chatID As String = “YOUR_CHAT_ID” ’ Replace with your chat ID
Dim messageText As String
Dim wsSummary As Worksheet
Dim tableRange As Range
Dim tableData As Variant
Dim i As Long, j As Long
Dim response As String

' Check if "SummaryReport" sheet exists
On Error Resume Next
Set wsSummary = ThisWorkbook.Sheets("SummaryReport")
If wsSummary Is Nothing Then
    MsgBox "Sheet 'SummaryReport' not found!", vbExclamation
    Exit Sub
End If
On Error GoTo 0

' Set the data range to be sent
Set tableRange = wsSummary.Range("A1:D18")
tableData = tableRange.Value

' Create the message
messageText = "📊 *Telkomcel Daily Report*" & vbCrLf
messageText = messageText & "📅 " & Format(Date, "dddd, mmmm dd, yyyy") & vbCrLf & vbCrLf

For i = 1 To UBound(tableData, 1)
    For j = 1 To UBound(tableData, 2)
        messageText = messageText & tableData(i, j) & " | "
    Next j
    messageText = messageText & vbCrLf
Next i

' Truncate if message is too long
If Len(messageText) > 4000 Then
    messageText = Left(messageText, 4000) & "... (truncated)"
End If

' Encode URL
messageText = Application.EncodeURL(messageText)

' Telegram API URL
URL = "https://api.telegram.org/bot" & botToken & "/sendMessage?chat_id=" & chatID & "&text=" & messageText & "&parse_mode=Markdown"

' Send request
On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", URL, False
http.Send
response = http.responseText
On Error GoTo 0

If InStr(response, """ok"":true") > 0 Then
    MsgBox "Report successfully sent to Telegram!", vbInformation
Else
    MsgBox "Failed to send report! Please check your bot token and chat ID.", vbCritical
End If

Set http = Nothing

End Sub

Thanks again for taking the time to assist!

Hi, thanks for your response and the helpful suggestions!

Just to share a bit more context, my automation reads from three Excel files, combines them into a multi-sheet workbook, and summarizes the result in a “SummaryReport” sheet. Then I call a VBA subroutine using the “Invoke VBA” activity to send the summary table via Telegram.

I’m currently using the HTTP request method in the VBA script to send the data. Here’s the part of the code I’m using inside the SendTelegramReport subroutine:

’ URL encode for Telegram
messageText = URLEncode(messageText)

' Format URL API Telegram
URL = "https://api.telegram.org/bot" & botToken & "/sendMessage?chat_id=" & chatID & "&text=" & messageText & "&parse_mode=Markdown"

' Send to Telegram
On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", URL, False
http.Send
response = http.responseText
On Error GoTo 0

' Check whether it is successful or not
If InStr(response, """ok"":true") > 0 Then
    MsgBox "Laporan berhasil dikirim ke Telegram!", vbInformation
Else
    MsgBox "Gagal mengirim laporan! Periksa token bot dan chat ID.", vbCritical
End If

Set http = Nothing

End Sub

I’ve already saved the VBA code in a .txt file and pointed to it in the “Invoke VBA” activity. Also made sure the “Trust access to the VBA project object model” setting is checked in Excel Trust Center.

However, when running in unattended mode, the same error still appears related to that trust setting. Do you think this might still be due to Excel’s security settings on the robot machine? Or could it be related to how the workbook or macro is structured?

I’ll try your suggestion to recreate the Excel file as well. Thanks again for your help—really appreciate the insight!

@nashwasabila11

  1. It can be related to robot machine settings
  2. Why not perform the api call via UiPath http request directly? then you dont need vba also

cheers