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 / VBScript Action in PAD...
Power Automate
Unanswered

VBScript Action in PAD - how to reference a dynamic column in the Run VBScript action?

(0) ShareShare
ReportReport
Posted on by 64

I am running the following VBScript in Power Automate Desktop. The cell "H2" and the range "H2:H17" will have a dynamic column (i.e. column H in this example), so how do I make the column dynamic in this VBScript action? 

 

MCubedMama_0-1710987395992.png

 

I have the same question (0)
  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @MCubedMama 

    Simply define two variables for the starting index and ending index, then incorporate them into your VB script as shown below:

     

    Deenuji_1-1710993476257.png


    Complete flow screenshot:

    Deenuji_2-1710993515094.png

     

    Code:

     

    SET ExcelPathStats TO $'''C:\\Deenu\\Dates.xlsx'''
    SET StartingIndex TO $'''D3'''
    SET EndingIndex TO $'''D17'''
    @@copilotGeneratedAction: 'False'
    Scripting.RunVBScript.RunVBScript VBScriptCode: $'''\' VBScript to open, manipulate, and close an Excel workbook
    
    \' Create an Excel application object
    Set objExcel = CreateObject(\"Excel.Application\")
    objExcel.Visible = True \' Make Excel visible
    
    \' Open the workbook
    Set objWorkbook = objExcel.Workbooks.Open(\"%ExcelPathStats%\")
    Set objWorksheet = objWorkbook.Worksheets(\"Stats\") \' Specify the worksheet name
    
    \' Copy formula from H2 and paste it to the range H2:H17
    objWorksheet.Range(\"%StartingIndex%:%EndingIndex%\").Formula = objWorksheet.Range(\"H2\").Formula
    
    \' Save and close the workbook
    objWorkbook.Save
    objWorkbook.Close
    
    \' Quit Excel
    objExcel.Quit
    
    \' Release objects
    Set objWorksheet = Nothing
    Set objWorkbook = Nothing
    Set objExcel = Nothing''' ScriptOutput=> VBScriptOutput

     

     

    How to copy and paste the above code in your PAD?

    Deenuji_3-1710993578885.gif


    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 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard