Run office script with arguments

Tim Dörries 6 Reputation points
2023-01-03T20:18:17.403+00:00

Hi everyone,

in an Excelworksheet, i want to run an OfficeScript with arguments.

This sheet got some tables, and in condition, wich table (-name) i want to "analyze", the OfficeScript got in addtion to the standard-argument a second argument.

So i created a script with the following signature: "function main(workbook: ExcelScript.Workbook, tabName: string)".

My first idea is, to place some buttons in my sheet, and give them an argument. Is there a pissibility, to give my buttons some arguments?

275824-image.png

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 61,111 Reputation points
    2023-01-03T21:39:25.997+00:00

    It is unclear what kind of "arguments" you actually are needing. Do you want to prompt the user for some input? Is the data coming from a row that the button is on or the worksheet it is contained in?

    In general, you can get to the active worksheet that is triggering a macro and the data in that spreadsheet (such as the selected rows). So you don't need to pass any data to a handler for this. If you want user input when the button is clicked then the handler is responsible for getting that from the user. But ideally your macro shouldn't need any data outside the spreadsheet itself.

    0 comments No comments

  2. Tim Dörries 6 Reputation points
    2023-01-04T08:18:01.987+00:00

    Hi cooldadtx,

    i want to have an solution, like this question on stackoverflow: https://stackoverflow.com/questions/71444677/is-there-any-way-to-have-event-handling-with-excelscript-excel-for-web

    "[...] For every worker in the form, there has to be in the adjacent rows a Check IN and a Check OUT button that will stamp in the cell underneath the button the current time [...]"

    There is posted a solution with using the add-in JADE, but since my administrator disallow to add some addins, this is no option for me.

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

    In my case, i've got 4 different tables in the worksheet, and for each table, i need to handle content with a button.

    for example in vba i would create a solution like this:

    sub button1_clicked()
    makeSomething "table1"
    end sub

    sub button2_clicked()
    makeSomething "table2"
    end sub

    sub makeSomething(ByVal tableName as string)
    ... some code ...
    end sub

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

    First, i will create now 4 different scripts with nearly the same content.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.