Quiting applications preventing hanging if unsaved docs are open

I have a script that backs up Outlook.

In order for this to work properly I need to quit many things.

tell application "Microsoft Outlook" to quit
tell application "Microsoft Database Daemon" to quit
tell application "Microsoft Office Reminders" to quit
tell application "My Day" to quit
tell application "Microsoft Word" to quit
tell application "Microsoft Excel" to quit
tell application "Microsoft PowerPoint" to quit
tell application "Microsoft Messenger" to quit

However if there is an unsaved document the script hangs. How do I fix this?

Well you could check if it has open documents first, and if so then save them, then quit. For example for Excel something like this would work.

tell application "Microsoft Excel"
	-- make sure all of the workbooks are saved
	set theWorkbooks to workbooks
	repeat with aWorkbook in theWorkbooks
		tell aWorkbook
			if not saved then save
		end tell
	end repeat
	
	quit
end tell

Note that it probably won’t work if you have an unsaved “Untitled” document. You would have to supply a path of where to save the Untitled workbook since it doesn’t have a path yet. So the code needs a little more work… I’m only giving an example. You’ll have to work out all the details for each separate application because they’ll all require different code.

Thanks, that helps, problem is I am not a champion on AppleScript. So how would I not automatically safe it but simple pop up the document and allowing me to safe it or not?