[Office Script] Setting object transparency based on list of object names and boolean.

Rootero

New Member
Joined
Jun 24, 2019
Messages
6
Hi all, I am somewhat familiar with VBA, but I am new to office script - so please be patient with me.

I am seeking to create an organigram for teams of variable sizes and compositions. I have a table of names and roles, which populate specific elements in the organigram (the structure of which is fixed). However, as the teams are of variable size the tool is meant to remove elements from the organigram which are not in use/vacant. The easiest way to do that is to set transparency to 100. Question: Is there a way for Office Script to go through the list of object names in a table and set the transparency to 0 or 100 depending on a simple boolean parameter? As I cannot wrap my head around how to do this, any help is appreciated.

Thank you very much in advance!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I have put together this code, which does run, but does not make any changes. Please do advise.

Code:
function main(workbook: ExcelScript.Workbook) {
    let sheet = workbook.getActiveWorksheet();
   
 // Making a list of transparency values from Column G
    let listRange = sheet.getRange("G1").getEntireColumn().getUsedRange();
    let listValues = listRange.getValues();

    sheet.getShapes()
        .forEach(shape => {
            let shapeName = shape.getName();
            // Find the shape name in Column H and return the transparency value in the same row
            let transparencyValue = listValues.find(row => row[1] === shapeName);
            // if a value is defined, set shape transparency to value
            if (transparencyValue) {
                shape.select();
                shape.getFill().setTransparency(transparencyValue[0]);
            }
        });
}
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top