r/excel • u/fabtec-lazer • Jun 30 '26
unsolved Office Script can’t append to a protected worksheet - best practice?
I’m building an Excel Online workbook in Microsoft Teams that uses an Office Script to complete preventive maintenance (PM) records.
Current workflow:
User completes a PM on a “PM Completion” sheet.
Office Script appends a new row to a “PM History” sheet.
The script also creates a Repair Log entry if any checklist item is marked as an issue.
Everything works correctly while the PM History sheet is unprotected.
If I protect the PM History sheet (to prevent users from editing historical records), the Office Script fails when it tries to append the new row.
My goal is to keep PM History as a read-only audit log while still allowing the Office Script to write new records.
My questions are:
Is this an expected limitation of Office Scripts with protected worksheets?
Is there a recommended pattern for this?
Temporarily unprotect and re-protect in the script?
Store data on another sheet and copy it?
Leave history unprotected and rely on workbook permissions?
How are people building protected audit logs in Excel Online/Teams with Office Scripts?
I’d appreciate hearing how others have solved this.
•
u/AutoModerator Jun 30 '26
/u/fabtec-lazer - Your post was submitted successfully.
Solution Verifiedto close the thread.Failing to follow these steps may result in your post being removed without warning.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/fabtec-lazer Jun 30 '26
Wanted to add:
This is for a production maintenance system used by multiple supervisors, so I’m looking for a robust long-term solution rather than a temporary workaround.
2
u/JimFive Jun 30 '26
I haven't tried this.
You used to be able to select which cells are protected in a sheet with a checkbox in the cell formatting.
Unprotect all the cells. Then after adding the log row protect the cells by "checking the box" (however you do that in the script).
3
u/taylorgourmet 4 Jun 30 '26
With VBA you can easily unprotect and protect sheets. I imagine office scripts has something similar but never used it.
2
u/Mdayofearth 127 Jun 30 '26
If you really need to protect something, don't use Excel.
That said, best practice is to unprotect then reprotect the worksheet.
0
u/[deleted] Jul 01 '26
[removed] — view removed comment