Results 1 to 6 of 6

VBA Script Applying to other open workbooks

Threaded View

trevryan82 VBA Script Applying to other... 04-01-2021, 12:37 PM
TMS Re: VBA Script Applying to... 04-01-2021, 03:31 PM
trevryan82 Re: VBA Script Applying to... 04-01-2021, 06:33 PM
TMS Re: VBA Script Applying to... 04-01-2021, 06:45 PM
trevryan82 Re: VBA Script Applying to... 04-01-2021, 06:53 PM
TMS Re: VBA Script Applying to... 04-01-2021, 06:56 PM
  1. #1
    Registered User
    Join Date
    07-23-2019
    Location
    Rapid City
    MS-Off Ver
    Standard 2016
    Posts
    13

    VBA Script Applying to other open workbooks

    I am using a login form to customize which sheets to display based on who logs in. It works fine (though I know it's not the cleanest code) but if another workbook is open, I get "Subscript out of range." It appears to me that it is trying to find worksheets in the already open workbook instead of the one that is being logged into.

    Instead of telling users they have to close all open workbooks before opening this one, is there a way to handle this error?

    Code is below:

    Private Sub cmdLogin_Click()
    
    Dim user As String
    Dim password As String
    
    user = Me.txtUserID.Value
    password = Me.txtPassword.Value
    
    If (user = "admin" And password = "mon57701") Or (user = "rcsales" And password = "lifesong") Or (user = "showroom" And password = "update") Then
    
    
    'THIS SECTION IS USED TO CUSTOMIZED LOGIN
    If user = "rcsales" Then
    Unload Me
    Worksheets("LifeSong Report").Visible = False
    Worksheets("RileyStatus2021").Visible = True
    Worksheets("RileyStatus2021").Protect
    Worksheets("RileySort").Visible = False
    Worksheets("RileySales").Visible = True
    Worksheets("RileySales").Protect
    Worksheets("NCOCalc").Visible = False
    Worksheets("COMMRATE").Visible = False
    Worksheets("SFSales").Visible = False
    Worksheets("Targets").Visible = True
    Worksheets("Targets").Protect
    Application.Visible = True
    frmAdminMenu.Show
    
    
    ElseIf user = "admin" Then
    Unload Me
    Worksheets("LifeSong Report").Visible = True
    Worksheets("RileyStatus2021").Visible = True
    Worksheets("RileyStatus2021").Unprotect
    Worksheets("RileySort").Visible = False
    Worksheets("RileySales").Visible = True
    Worksheets("RileySales").Unprotect
    Worksheets("NCOCalc").Visible = True
    Worksheets("COMMRATE").Visible = False
    Worksheets("SFSales").Visible = True
    Worksheets("Targets").Visible = True
    Worksheets("Targets").Unprotect
    Application.Visible = True
    frmAdminMenu.Show
    
    Else
    Unload Me
    Worksheets("LifeSong Report").Visible = False
    Worksheets("RileyStatus2021").Visible = False
    Worksheets("RileyStatus2021").Protect
    Worksheets("RileySort").Visible = False
    Worksheets("RileySales").Visible = True
    Worksheets("RileySales").Unprotect
    Worksheets("NCOCalc").Visible = False
    Worksheets("COMMRATE").Visible = False
    Worksheets("SFSales").Visible = False
    Worksheets("Targets").Visible = False
    Worksheets("Targets").Protect
    Application.Visible = True
    frmAdminMenu.Show
    
    
    End If
    Attached Files Attached Files
    Last edited by trevryan82; 04-01-2021 at 06:46 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Applying same formula to multiple workbooks
    By hollacost69 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2020, 05:32 PM
  2. Replies: 1
    Last Post: 03-31-2016, 02:06 AM
  3. Applying and saving an auto_open macro to all open workbooks
    By kfryar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2014, 04:20 AM
  4. Replies: 2
    Last Post: 03-29-2013, 06:19 PM
  5. Use of Workbooks.Open in VB Script in Excel 2010 for a web source spread sheet hangs
    By PeterGammage in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2013, 01:26 PM
  6. Applying formula from different workbooks
    By excel5111987 in forum Excel General
    Replies: 0
    Last Post: 09-09-2011, 07:20 AM

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