Hi Eric,

Thanks for help!!!!!!!

I tried
1. Run menu in the script editor UI
2. custom menu

Both Are functional and solved my problem

-----
*Sample Code for other to help in future:*
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('UpdateSheet')
      .addSubMenu(ui.createMenu('Freeze')
                  .addItem('Columns', 'freezesColumns')
                  .addSeparator()
                  .addItem('Rows', 'freezesRows')
                  .addSeparator()
                  .addItem('Both', 'freezesAll')
                  .addSeparator()
                  .addItem('None', 'unfreeze'))
      .addToUi();
}
var totalSheetsCount = SpreadsheetApp.getActiveSpreadsheet().getNumSheets();

function freezesColumns(){
   for(var i = 1; i < totalSheetsCount; i++) {
   SpreadsheetApp.getActiveSpreadsheet().getSheets()[i].setFrozenColumns(8);
   }
};

function freezesRows(){
   for(var i = 1; i < totalSheetsCount; i++) {
      SpreadsheetApp.getActiveSpreadsheet().getSheets()[i].setFrozenRows(2);
   }
};

function freezesAll(){
  freezesRows();
  freezesColumns();
};

function unfreeze(){
  for(var i = 1; i < totalSheetsCount; i++) {

SpreadsheetApp.getActiveSpreadsheet().getSheets()[i].setFrozenColumns(0);
    SpreadsheetApp.getActiveSpreadsheet().getSheets()[i].setFrozenRows(0);
   }
};

---
Above code will give u below options

​

On Tue, Aug 23, 2016 at 10:42 PM, bolleypally vijay kumar <
[email protected]> wrote:

> Thanks Eric I will try that
>
> On Aug 23, 2016 10:06 PM, "'Eric Koleda' via Google Spreadsheets API" <
> [email protected]> wrote:
>
>> The code looks good, you just need to find another way to run it. Custom
>> functions are used to calculate values, not to alter the spreadsheet. You
>> can use the run menu in the script editor UI to run it, or add a custom
>> menu to your spreadsheet:
>>
>> https://developers.google.com/apps-script/guides/menus
>>
>> - Eric
>>
>> On Tuesday, August 23, 2016 at 5:31:21 AM UTC-4, bolleypally vijay kumar
>> wrote:
>>>
>>>
>>> I have a Spreadsheet with 15 sheets i would like to freeze first 2 rows
>>> of each sheet using code in .js file that is associated with my spreadsheet
>>>
>>> Code i wrote in .gs file
>>>
>>> function freezesColumns(){
>>> var totalSheetsCount = SpreadsheetApp.getActiveSpread
>>> sheet().getNumSheets();
>>>    for(var i = 1; i <= totalSheetsCount; i++) {
>>>      var eachSheet = SpreadsheetApp.getActiveSpread
>>> sheet().getSheets()[i];
>>>      eachSheet.setFrozenRows(2);
>>>    }
>>> }
>>>
>>> and called this method in any cell i the spreadsheet =freezesColumns()
>>>
>>> Error Details:No Permission to call setFrozenRows(line no in .gs file)
>>>
>>>
>>> <https://lh3.googleusercontent.com/-gHpGa635MAo/V7wVsxZc6rI/AAAAAAAAB44/pNsSdX13W7cSgfL57Rm6u97RyJcH8iG3gCLcB/s1600/GSS.png>
>>>
>>>
>>> In my case number of sheets will increase every time and i want to make
>>> specific rows and columns freeze automatically with code.
>>>
>>>
>>> i also refereed Custom Functions in Spreadsheets
>>> <https://developers.google.com/apps-script/execution_custom_functions?hl=fr-FR>
>>>  documentation
>>> and got "*Custom functions cannot set values outside the cells they are
>>> in" **if its true how to use 'setFrozenRows' and 'setFrozenColumns' in
>>> API*
>>>
>>> Please help me make it possible
>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Google Spreadsheets API" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/google-spreadsheets-api/Cx0WZ_MAvmI/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>


-- 
*Men who try to do something and Fail are infinitely better than those*
*who try to do nothing ...*
*
          B.VIJAY*

-- 
You received this message because you are subscribed to the Google Groups 
"Google Spreadsheets API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to