+ Reply to Thread
Results 1 to 4 of 4

LOGIN Enabled Workbook - Problems Closing one of the sheets

Hybrid View

  1. #1
    Forum Contributor sorensjp's Avatar
    Join Date
    12-23-2015
    Location
    Yokosuka, JP
    MS-Off Ver
    2016, 2019, 365
    Posts
    198

    LOGIN Enabled Workbook - Problems Closing one of the sheets

    Hello,

    I'm trying to close a workbook and using Macros to Loop thru each worksheet to set as xlSheetVeryHidden with the exception of the LOGIN Sheet.

    The attached workbook is an .xlsb (recommend changing to.xlsm) file to reduce size. The MACRO operates properly if I'm on the LOGIN sheet (Normally Hidden after logging in). But when I'm on any other sheet and close the workbook I get a Run-time error '1004: Method 'Visible' of object'_Worksheet' failed.

    User Name & Password are either:
    USER -------- Pword
    admin ------- Cville62!!
    sorensjp -------- 515457

    I cannot understand why every sheet closes properly but Sheet 9 (WEAPS_QUAL_RPT).

    Thank you for taking the time to look at this issue and appreciate any advice.

    V/r,
    Jim
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: LOGIN Enabled Workbook - Problems Closing one of the sheets

    The reason you were getting the error was that only one sheet was visible at the time the CloseWorkbook macro was run and the macro was trying to make that one and only visible sheet not visible. Excel must have at least one sheet visible at all times. The macro below makes the LOGIN sheet visible first and then hides all the other sheets. I hope this makes sense. Also, you get a lot of screen flickering when you close the file. Try placing the code in your other macros between "Application.ScreenUpdating = False ….. Application.ScreenUpdating = True" statements as I have done.

    Try replacing your current macro with this one:
    Sub CloseWorkbook()
        Application.ScreenUpdating = False
        Dim WkSht As Worksheet
        With Sheets("LOGIN")
            .Visible = True
            .Range("B9").ClearContents
        End With
        For Each WkSht In ThisWorkbook.Worksheets
            If WkSht.Name <> "LOGIN" Then WkSht.Visible = xlSheetVeryHidden
        Next WkSht
        ThisWorkbook.Save
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor sorensjp's Avatar
    Join Date
    12-23-2015
    Location
    Yokosuka, JP
    MS-Off Ver
    2016, 2019, 365
    Posts
    198

    Re: LOGIN Enabled Workbook - Problems Closing one of the sheets

    Mumps1,

    Thank you. You solved it. I was going to hard code each sheet as to state:
    SheetXX.Visible = xlSheetVeryHidden
    vice
    For Each WkSht In ThisWorkbook.Worksheets
        If WkSht.Name <> "LOGIN" Then WkSht.Visible = xlSheetVeryHidden
        Next WkSht
    Does that make any sense?

    I just made this minor adjustment to what you wrote and works great:
    Sub CloseWorkbook()
    Application.ScreenUpdating = False
    Sheet11.Activate
    Sheet11.Visible = xlSheetVisible
    Sheet11.Range("B9").ClearContents
    Dim WkSht As Worksheet
    For Each WkSht In ThisWorkbook.Worksheets
        If WkSht.Name <> "LOGIN" Then WkSht.Visible = xlSheetVeryHidden
        Next WkSht
    ThisWorkbook.Save
    Application.ScreenUpdating = True
    
    End Sub
    Thank you, again for solving my issue. I was thinking I needed to do way more than just a couple lines.

    V/r,
    Jim

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: LOGIN Enabled Workbook - Problems Closing one of the sheets

    You are very welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help in login vba code to unhide specific sheets depends on login info
    By AlaaEddin95 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2019, 08:19 PM
  2. Creating new workbook, saving as csv and then closing - but closing always fails.
    By ella626 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2014, 10:05 PM
  3. [SOLVED] Macro to Saving Workbook Sheets as Separate Macro-Enabled Workbooks
    By puppetpalace in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-03-2013, 01:58 PM
  4. lock and hide particular sheets automatically after closing workbook
    By jeevan123 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-26-2012, 06:53 AM
  5. macro enabled workbook problems
    By devonkay in forum Excel General
    Replies: 1
    Last Post: 03-30-2009, 11:28 PM
  6. closing a workbook without saving and closing a workbook with saving enabled
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2007, 02:15 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1