web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Is it possible to writ...
Power Automate
Unanswered

Is it possible to write a full datatable into Excel using a SQL Connection rather than Excel actions?

(2) ShareShare
ReportReport
Posted on by 40

Reading from an Excel spreadsheet is much faster using a SQL connection and I'm successfully using this to pull my excel data into a new datasheet in my flow.

 

I would like to do the same thing in reverse, instead of reading from an Excel sheet, I want to write from a DataTable to Excel. I've tried a few variations of the following but it keeps failing with the error "Error in SQL statement Syntax error in FROM clause". I don't know if this is just not possible, or if I'm just not using the correct syntax.

 

INSERT INTO [Trimmed$] ([Date_and_Time],[Zip_Code],[Brand],[Station_ID],[Adress],[Price],[Reported_by],[Age],[Time_Reported])
SELECT [Date_and_Time],[Zip_Code],[Brand],[Station_ID],[Adress],[Price],[Reported_by],[Age],[Time_Reported]
FROM %Excel_Write%

INSERT INTO [Trimmed$] (Date_and_Time,Zip_Code,Brand,Station_ID,Adress,Price,Reported_by,Age,Time_Reported)
SELECT *
FROM %Excel_Write%

INSERT INTO [Trimmed$] (Date_and_Time, Zip_Code, Brand, Station_ID, Adress, Price, Reported_by, Age, Time_Reported)
SELECT Date_and_Time, Zip_Code, Brand, Station_ID, Adress, Price, Reported_by, Age, Time_Reported
FROM %Excel_Write%

 

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Jagster ,

     

    You can try with VBscript.Please find the VBscript for the above approach.

     

    Vbscript:

    ' Create Excel application
    Dim excelApp, workbook, sheet
    Set excelApp = CreateObject("Excel.Application")
    
    ' Make Excel visible (optional)
    excelApp.Visible = True
    
    ' Add a new workbook
    Set workbook = excelApp.Workbooks.Add
    
    ' Select the first sheet
    Set sheet = workbook.Sheets(1)
    
    ' Write the column headers
    Dim colIndex, rowIndex
    For colIndex = 0 To rs.Fields.Count - 1
     sheet.Cells(1, colIndex + 1).Value = rs.Fields(colIndex).Name
    Next
    
    ' Write the data to the Excel sheet
    rowIndex = 2
    Do Until rs.EOF
     For colIndex = 0 To rs.Fields.Count - 1
     sheet.Cells(rowIndex, colIndex + 1).Value = rs.Fields(colIndex).Value
     Next
     rs.MoveNext
     rowIndex = rowIndex + 1
    Loop
    
    ' Save the workbook
    Dim savePath
    savePath = "C:\path\to\your\output.xlsx"
    workbook.SaveAs savePath
    
    ' Close the workbook and clean up
    workbook.Close
    excelApp.Quit
    
    Set rs = Nothing
    Set conn = Nothing
    Set workbook = Nothing
    Set excelApp = Nothing

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • Sayan Profile Picture
    818 Moderator on at

    Hey @Jagster 

     

    You can use the Follow solution:

     

    Main Workflow:

    Sayan_0-1721023177476.png

     

     

    Step 1:

    Read Data from Excel Worksheet.

     

    Step 2:

    Use Action writes to Excel Worksheet.

     

    Code:

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\SayanPatra\\Downloads\\challenge.csv''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: ExcelData Column: $'''A''' Row: 15
    Excel.CloseExcel.CloseAndSave Instance: ExcelInstance

     

     

    ------------------------------------------------------------------------------------------------------------------------------

    If my solution helps you, please gives it a Thumbs up 👍 and Marks as a Solution ✔️. Which motivates to solve more problems.

    Thanks,

    Sayan Patra | RPA Developer

  • Jagster Profile Picture
    40 on at

    @VishnuReddy1997 wrote:

    Hi @Jagster ,

     

    You can try with VBscript.Please find the VBscript for the above approach.

     


    Thank you Vishnu. I'm really looking for a SQL method, if possible, to avoid opening the Excel app in the process. If using a SQL statement is not possible, I will certainly look at your VBScript method but I'm not sure how differently it will be since it also opens the Excel executable to write.

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Jagster ,

     

    I dont think there is a method to write into excel using SQL.

    Its better using VBscript method only.

     

    Regards,

    Vishnu Reddy

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 237 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 227 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 194

Last 30 days Overall leaderboard