ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   closing current file only (https://www.excelbanter.com/excel-programming/275439-closing-current-file-only.html)

Adam[_8_]

closing current file only
 
How do I make it so that when a user clicks the Excel Right Hand close
(X) it shuts down my file1.xls and not all the other open excel files
or the excel application. This is what i've currently using but i'm
not happy with it closing all other peoples excel files. I'm a quite
new to VB but picking it up as I go along.



Sub auto_close()
Sheets("Intro").Visible = True
Sheets("IC").Visible = False
Sheets("PCP").Visible = False

Dim response As Integer
Dim Names As Range
Set Names = Sheets("DATA").Range("B1")
response = MsgBox(prompt:="Are you sure " & Names & " you want
to exit?", Buttons:=vbYesNo)
If response = vbYes Then

ThisWorkbook.Save
Toolbars(1).Visible = True
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.CommandBars("Formatting").Enabled = True
Application.CommandBars("Standard").Enabled = True
Application.DisplayFormulaBar = True
Application.CommandBars("Formatting").Visible = True
Application.Caption = "Microsoft Excel"
ActiveWorkbook.Close


Else: ExecuteExcel4Macro "HALT(TRUE)"


End If



End Sub


All times are GMT +1. The time now is 09:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com