Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Closing a File

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Location
    Mike Golding
    Posts
    71
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I run a Macro from a button to close Excel which is OK when I have only one file open. I can't create a Macro to close just the current file. (With the offer to save)Some help would be great, thanks.

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-08 22:08, Mike E Golding wrote:
    I run a Macro from a button to close Excel which is OK when I have only one file open. I can't create a Macro to close just the current file. (With the offer to save)Some help would be great, thanks.

    Activeworkbook.Close

    Ivan

  3. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    ...Or

    Sub CloseOrQuit()
    Dim IwbCount As Integer
    On Error Resume Next

    IwbCount = 2
    If Workbooks("Personal.xls") Is Nothing Then
    IwbCount = 1
    End If

    On Error GoTo 0
    If Application.Workbooks.Count > IwbCount Then
    ActiveWorkbook.Close
    Else
    Application.Quit
    End If

    End Sub

    _________________
    Kind Regards
    Dave Hawley
    OzGrid Business Applications
    Microsoft Excel/VBA Training
    If it's Excel, then it's us!

    [ This Message was edited by: Dave Hawley on 2002-03-09 01:35 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •