Consulting

Results 1 to 9 of 9

Thread: Solved: Disable "X" Button on ActiveWorkBook

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Solved: Disable "X" Button on ActiveWorkBook

    I can use the Application.Hwnd property and the RemoveMenu API to disable the Close [X] button on an instance of Excel.

    Additionally I can issue Application.CommandBars("File").Enabled = False to disable the File Menu.

    I then load a template for data entry and assume for all intensive purposes that the user cannot close Excel, or perform file I/O. However, the user can still click the X on the ActiveWorkbook and close the template. My question: is their a way to disable the Close Button on the Activeworkbook? Stan

  2. #2
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    Sure,
    Justin Labenne

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This is a poor programming technique IMO, as you are stopping the user from doing things that other workbooks permit. I would suggest that it is better to interecept the BeforeClose event, and do whatever you want to do there.

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Justin;

    Your code disables the X on the Application, not the ActiveWorkbook (see attached jpg - I want to disable X on the RemoveX child window, not the Excel main window).

    Stan

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by xld
    This is a poor programming technique IMO, as you are stopping the user from doing things that other workbooks permit. I would suggest that it is better to interecept the BeforeClose event, and do whatever you want to do there.
    XLD;

    While I agree in general, in this particular application the user never runs Excel - they run a .wsc that opens the Excel Object then the template file - there is no macro code in the template, and I don't want any. The user can enter data, but must click on the floating toolbar [created by the .wsc] to save and close the workbook and Excel object. See attached jpg - it is a test template, not the real thing.

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    I figured it out. Needed to 'hijack' the WorkBookBeforeClose() event and set Cancel=True. But then I needed to release the event after my floating toolbutton is pressed so that Excel Object could be closed normally.
    Stan

  7. #7
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    Glad you figured it out. Sorry for misreading......to remove the window close:

    [VBA]Option Explicit

    Public Sub RemoveWindowX()
    ActiveWorkbook.Protect , , True
    End Sub

    Public Sub RestoreWindowX()
    ActiveWorkbook.Protect , , False
    End Sub[/VBA]
    Justin Labenne

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by stanl
    XLD;

    While I agree in general, in this particular application the user never runs Excel - they run a .wsc that opens the Excel Object then the template file - there is no macro code in the template, and I don't want any. The user can enter data, but must click on the floating toolbar [created by the .wsc] to save and close the workbook and Excel object. See attached jpg - it is a test template, not the real thing.
    and yet you plaster the Excel icon all over it?

  9. #9
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by xld
    and yet you plaster the Excel icon all over it?
    To repeat: "it is a test template, not the real thing"

Posting Permissions

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