Results 1 to 5 of 5

Thread: Excel 97, CLOSE ALL FILES but...

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Excel 97, CLOSE ALL FILES but...

    Question:

    Using Excel 97, I have several workbooks open.
    My program takes control of excel, removing user access to all menus, shortcuts, etcs. The only means of closing the program that i leave them is the X on the top right corner.

    We are experimenting to find a way to close all "my" open files.

    Currently, we use DisplayAlerts= false, and Application.quit
    with each file of my program saving automically with no user input required.

    BUT *There's always a BUT.

    a) if there are no open files from my program, close the application, using application.quit
    b) if the user had files open prior, to close all my files, but to leave the user in Excel

    Any suggestions on how to accomplish this?
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Hey FIDDLER, been a while. The only things I could think of right
    away was to create some kind of running list of open workbooks
    when your program starts. The upon quit, loop through the
    workbooks collection checking to see if any of those are open. If
    so prompt to save them or ???

    The other thing I was thinking was to add some other kind of
    hidden property in all of your workbooks. Then upon close if the
    workbook doesnt have the property, prompt for save or ???

    HTH
    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

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    AHHH!! THis is my third time trying to post tonight! I keep losing my post and getting a message saying that I am not logged in.

    Actually, What I am trying to do is disable the WIndow.Close X on the top right corner so that I can force a close only via an Exit button that I will place on the form.

    I can identify my open workbooks fairly simple. They all start with the same characters for the workbook name, so I can simply read through the workbook collection looking for them. Or I can add them to a list array as they are opened, and loop through this list array with a close command.

    Then my code will be something like this:

    For each workbook in myworkbooks
    myworkbooks.close (simple to do, since I opened them)
    Next
    If workbooks.count >1 then
    leave excel open
    Else
    Application.quit
    End if

    So any suggestions on how to disable or to take control of the Windows CLose Program X. Ideally, I would like this code to be activated by the X and me not having to code a separate Exit button, but I think it's easier to disable the X and write my own exit button.

    btw: want to see something neat?
    CHeck out my post to Classic VB Forums several days ago. We spent hours trying to find the error in the code. Neat little compiler glitch.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  4. #4

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    I should mention that there is no user access to any of the menu bars, save the Windows bar (Minimize, Maximize and Close).

    Coding it would be a lot simpler is the File Close X would showing. I am trying to do this using the Windows X, or a button that calls the same file.close as the file close X would.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I'm not too sure which way you need this, but here is an example
    that will remove the cose system menu, thereby disabling the 'x'.
    This is for VB and not too sure if can be converted to Excel since I
    currently don't have Office on my new system.

    VB Code:
    1. Private Const MF_BYPOSITION = &H400&
    2.  
    3. Private Declare Function RemoveMenu Lib "user32" _
    4. (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    5.  
    6. Private Declare Function GetSystemMenu Lib "user32" _
    7. (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    8.  
    9. Private Sub Form_Load()
    10.     RemoveMenu GetSystemMenu(hwnd, 0), 6, MF_BYPOSITION
    11. End Sub
    12.  
    13. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    14.     If UnloadMode = vbFormCode Then Cancel = True
    15. End Sub
    HTH
    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