Results 1 to 2 of 2

Thread: Cannot close WorkBooks ...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    115

    Angry Cannot close WorkBooks ...

    I tried other ways of closing it, but it is still in the Tast Manager ...
    It opens it up and that's it ... how the hell do I close it
    I use Microsoft Excel 11.0 Lib.

    here is the code

    VB Code:
    1. Public Sub Check_Validity2()
    2. On Error GoTo NoFile
    3.     Set myBook = Workbooks.Open(strMainFilePath)
    4.     exists = myBook.Worksheets("AH Data").Cells(1, 3).Value
    5.     If exists = "AH1 (AH09-01)" Then
    6.         exists = "true"
    7.     Else: exists = ""
    8.     End If
    9.     myBook.Close savechanges:=False
    10. NoFile:
    11.     If Err.Number = 9 Then
    12.     myBook.Close
    13.     exists = ""
    14.     End If
    15. End Sub
    Last edited by RobDog888; Mar 28th, 2005 at 11:23 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot close WorkBooks ...

    I take it that this is entirely in Excel. So, you are wanting to close the workbook AND close Excel.
    This will close the Excel application if you have already closed the workbook.
    After you close the workbook you need to destroy the workbook object.

    VB Code:
    1. myBook.Close
    2. Set mybook = Nothing
    3. Application.Quit
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width