1

I'm looking to auto-populate the document's name into a single cell in sheets no matter if/when the doc name is changed. I can enter a formula from a script =DocName(), but it won't update when the document name is changed.

The script I used was

function DocName() { return SpreadsheetApp.getActive().getName(); }

I tried combining the =DocName() function with =IF(TODAY()=TODAY() but kept getting errors no matter how I formatted it.

5
  • 1
  • 1
    Does this answer your question? How to make that a custom function update its result immediately
    – Tedinoz
    Jan 7, 2022 at 0:32
  • Tedinoz unfortunately no it doesn't. That is referencing sheet names, not the entire document name. I'm looking for the document name to auto-populate as a header on each of the sheets within the document.
    – Denny
    Jan 7, 2022 at 3:05
  • I don’t think you have read and understood the answer to that post. Whether it is the sheet name OR the document name is of no consequence because neither will work in a custom function. Why? Because something has to trigger it, and functions like NOW and TODAY don’t work in a custom function. You need to explore a work-around, and there are a few covered in Ruben’s answer. There are also many precedents on WebApps and StackOverflow for this kind of question, so some research there would be productive.
    – Tedinoz
    Jan 7, 2022 at 4:05
  • This was my first exploration of scripts, so you're right. I didn't understand what I was reading or if the answer I was looking for was there. I come here because I know there are others that know more than myself and humbly ask questions not knowing where to start research. Thanks for your help.
    – Denny
    Jan 8, 2022 at 21:56

1 Answer 1

0

I found a script that worked here, where it forces the custom function I mentioned in my original post to run on open, updating the cell with the name of the document.

1
  • Indeed, a work around.
    – Tedinoz
    Jan 7, 2022 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.