What is VBA Target.Calculate syntax for Office Script

Ben Benitez 0 Reputation points
2025-11-20T15:17:32.79+00:00

I uploaded a macro enabled spreadsheet in OneDrive. I want to highlight the entire row automatically on mouse click. I found workbook.getApplication().calculate(ExcelScript.CalculationType.full); but I still need to press DELETE key to highlight the entire row.

Is there another syntax that highlight the entire row automatically without pressing the DELETE key?

I didn't find exact same question about this, so I apologize if there is.

Thank you in advance.

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

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-20T15:17:54.29+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In Office Scripts, there isn't a direct equivalent to the VBA Target.Calculate syntax that allows you to highlight an entire row automatically on mouse click without additional key presses. However, you can achieve the desired functionality by using the getRange method to select the entire row based on the active cell's position. Here’s a simple example of how you can highlight the entire row of the active cell:

    function main(workbook: ExcelScript.Workbook) {
        // Get the active cell's range
        let activeCell = workbook.getActiveCell();
        // Get the entire row of the active cell
        let entireRow = activeCell.getEntireRow();
        // Clear previous highlights
        workbook.getActiveWorksheet().getRange("1:1048576").getFormat().getFill().clear();
        // Highlight the entire row
        entireRow.getFormat().getFill().setColor("#00FFFF"); // Set your desired highlight color
    }
    

    This script retrieves the active cell, gets its entire row, clears any previous highlights, and then applies a new highlight color to that row. You can run this script whenever you want to highlight the row of the active cell without needing to press the DELETE key.


    References:

    0 comments No comments

  2. Aron 7,190 Reputation points Independent Advisor
    2025-11-20T15:57:44.06+00:00

    Hi there, I understand how important it is to have the row highlight happen automatically.

    The reason it’s not working as expected is that Office Scripts doesn’t support real-time event triggers like VBA does, so actions such as clicking a cell won’t fire a script on their own.

    Right now, the script only runs when you manually execute it or set up an automation flow.

    A quick step you can try is to confirm that the script highlights the active row when you run it manually, if that works, the next step would be using Power Automate to trigger the script whenever the workbook changes.

    Can you tell me if running the script manually highlights the row correctly?

    Also, do you want this to happen only on selection or whenever any cell value changes?

    Regards,
    Aron

    0 comments No comments

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.