slamet Harto
12-22-2008, 12:14 AM
Hi there,
just have two problem,
1) I have the following code to exit excel application with condition.
For instance:
we have more than 1 workbook open then want to save before close. If
the workbook name is different with current workbook opened.
what I want is to save all the workbook open with:
if the workbook is read only then ask user to save to different filename
or if the workbook open with different name with current wb open then
save the workbook
Sub ExitApps()
Dim Wb As Workbook
On Error Resume Next
Application.CommandBars("MyCommandBarName").Delete
With Application
.DisplayAlerts = False
Sheet1.Visible = xlSheetVisible
Sheets("template").Visible = xlSheetVeryHidden
.CommandBars("Worksheet Menu Bar").Enabled = True
.CommandBars("Formatting").Visible = True
.CommandBars("Drawing").Visible = True
.CommandBars("Standard").Visible = True
.CommandBars("Control Toolbox").Visible = False
.MoveAfterReturnDirection = xlDown
.DisplayFormulaBar = True
End With
With Application
.ScreenUpdating = False
For Each Wb In Workbooks
With Wb
If Not Wb.ReadOnly Or Wb.Name <> ThisWorkbook.Name Then
.Save
Else
.Close SaveChanges:=False
Application.Quit
End If
End With
Next Wb
Application.DisplayAlerts = False
Application.ScreenUpdating = True
Application.Quit
End With
End Sub
2) Is there a way to prevent close excel application thru X button . (the X button on the right top of excel application).
I know it can be done with userform which is declined user to close an userform. But I want to prevent the user to close the application thru "X" button in right top excel application.
Your advice would be appreciate so much.
Thanks & Rgds, Harto
just have two problem,
1) I have the following code to exit excel application with condition.
For instance:
we have more than 1 workbook open then want to save before close. If
the workbook name is different with current workbook opened.
what I want is to save all the workbook open with:
if the workbook is read only then ask user to save to different filename
or if the workbook open with different name with current wb open then
save the workbook
Sub ExitApps()
Dim Wb As Workbook
On Error Resume Next
Application.CommandBars("MyCommandBarName").Delete
With Application
.DisplayAlerts = False
Sheet1.Visible = xlSheetVisible
Sheets("template").Visible = xlSheetVeryHidden
.CommandBars("Worksheet Menu Bar").Enabled = True
.CommandBars("Formatting").Visible = True
.CommandBars("Drawing").Visible = True
.CommandBars("Standard").Visible = True
.CommandBars("Control Toolbox").Visible = False
.MoveAfterReturnDirection = xlDown
.DisplayFormulaBar = True
End With
With Application
.ScreenUpdating = False
For Each Wb In Workbooks
With Wb
If Not Wb.ReadOnly Or Wb.Name <> ThisWorkbook.Name Then
.Save
Else
.Close SaveChanges:=False
Application.Quit
End If
End With
Next Wb
Application.DisplayAlerts = False
Application.ScreenUpdating = True
Application.Quit
End With
End Sub
2) Is there a way to prevent close excel application thru X button . (the X button on the right top of excel application).
I know it can be done with userform which is declined user to close an userform. But I want to prevent the user to close the application thru "X" button in right top excel application.
Your advice would be appreciate so much.
Thanks & Rgds, Harto