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 / How to write datatable...
Power Automate
Unanswered

How to write datatable into word file using vb script in PAD?

(0) ShareShare
ReportReport
Posted on by 357

Hi Team,

I want to write my DataTable data into word file with table format with table border.
By using the vb script .
It should be dynamic. 
Means I want to pass data table variable every time.

It would be great if you provide me the vb script .

my flow is like this 

- Extract data from json
- Store it in DataTable

- Then write data table in word using vb script in PAD

thanks in advance!!!

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Sanket1 

     

    How is your data table dimension looks like? The data table has standard headers?

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Sanket1 Profile Picture
    357 on at

    Yes

     

    Data table has headers

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Sanket1 

     

    Still you are looking for any assistance on this? If yes please share some screenshot of your data table.

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Sanket1 Profile Picture
    357 on at

    My data table is look like this

    Sanket1_0-1718881805793.png

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    Hi @Sanket1 

     

    Try the below code:

    ' Sample data (simulated DataTable)
    Dim data
    data = Array( _
     Array("Sr. No.", "Raw Material", "Molecular Wt.", "Moles", "Mole Ratio", "Quantity", "Source", "A. R. No.", "Purity"), _
     Array(1, "Material A", 100.5, 2.0, 1.0, 50, "Source A", "AR-001", 98.5), _
     Array(2, "Material B", 200.2, 3.5, 2.0, 75, "Source B", "AR-002", 99.0), _
     Array(3, "Material C", 150.8, 1.8, 1.5, 60, "Source C", "AR-003", 97.0), _
     Array(4, "Material D", 180.0, 2.2, 1.2, 55, "Source D", "AR-004", 95.5), _
     Array(5, "Material E", 220.5, 4.0, 2.5, 80, "Source E", "AR-005", 96.0) _
    )
    
    ' Output file path
    Dim outputPath
    outputPath = "C:\Deenu\output.docx" ' Replace with your desired output path
    
    ' Create a Word document and add content
    Dim wordApp, doc, table, row, col
    
    ' Create Word application object
    Set wordApp = CreateObject("Word.Application")
    
    ' Make Word visible (for testing, you can set this to False to run in the background)
    wordApp.Visible = True
    
    ' Create a new document
    Set doc = wordApp.Documents.Add()
    
    ' Add a table at the end of the document
    Set table = doc.Tables.Add(doc.Range(), UBound(data) + 1, UBound(data(0)) + 1)
    
    ' Set table style (optional)
    table.Style = "Table Grid 1"
    
    ' Add column headers
    For col = LBound(data(0)) To UBound(data(0))
     table.Cell(1, col + 1).Range.Text = data(0)(col)
    Next
    
    ' Add data rows
    For row = LBound(data) + 1 To UBound(data)
     For col = LBound(data(row)) To UBound(data(row))
     table.Cell(row + 1, col + 1).Range.Text = data(row)(col)
     Next
    Next
    
    ' Save the document
    doc.SaveAs2 outputPath
    
    ' Close Word document
    doc.Close()
    
    ' Quit Word application
    wordApp.Quit()
    
    ' Release objects from memory
    Set table = Nothing
    Set doc = Nothing
    Set wordApp = Nothing
    
    WScript.Echo "Word document created successfully at: " & outputPath

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Sanket1 Profile Picture
    357 on at

    Thank yo so much for the script
    I want data table dynamic 

    I am dynamically adding data into datatable variable then that variable I want to pass it in vb script to write word file

    Could you please make modification accordingly?

     

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 249 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 202

#3
David_MA Profile Picture

David_MA 180 Super User 2026 Season 2

Last 30 days Overall leaderboard