closing current file only

A

Adam

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top