def close_workbook(wb, save):
    """
    provides a few conveniences that the client may not want to deal with
        1) if Workbook is the only one in the Excel application, closes the application as well
        2) correctly releases the com pointer for the workbook
    """
    if save and wb.ReadOnly:
        raise AssertionError("'{}' is open as read-only, cannot save and close"
            .format(wb.Name))
    excel_app = wb.Application
    display_alerts = excel_app.DisplayAlerts
    if save:
        wb.Save()
    excel_app.DisplayAlerts = False
    wb.Close()
    wb = None
    if excel_app.Workbooks.Count == 0:
        excel_app.Quit()
        excel_app = None
    else:
        excel_app.DisplayAlerts = display_alerts
