Skip to content

Instantly share code, notes, and snippets.

@SHi-ON
Created July 19, 2025 19:27
Show Gist options
  • Save SHi-ON/2e186b99e2da1c78b6c91f109f92c97a to your computer and use it in GitHub Desktop.
Save SHi-ON/2e186b99e2da1c78b6c91f109f92c97a to your computer and use it in GitHub Desktop.
Shell function for macOS to save all open Microsoft Excel workbooks and quit the application safely from the terminal.
# quitExcel.sh
#
# Function: quitExcel
#
# Description:
# Saves all open workbooks in Microsoft Excel and then quits the application,
# using AppleScript. Useful for closing Excel from the terminal and ensuring
# all data is saved.
#
# Usage:
# - Copy this function to your ~/.zshrc or ~/.bashrc
# - Source your shell config: source ~/.zshrc
# - Run `quitExcel` from the terminal
quitExcel() {
# Save all open workbooks in Microsoft Excel
osascript -e 'tell application "Microsoft Excel" to save every workbook'
# Quit Microsoft Excel
osascript -e 'tell application "Microsoft Excel" to quit'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment