+ Reply to Thread
Results 1 to 3 of 3

VBA code in Excel effecting other other excel worksheet/ workbook

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    VBA code in Excel effecting other other excel worksheet/ workbook

    I have VBA code in Excel which restrict access to a workbook depending on the user login detail, the workbook contains 11 sheets, worksheet are asigned to different user depending on the user login detail The problem I have is when i open other worksheet or workbook the VBA code starts to effect the other worksheet/ workbook, is there a way I can stop this from happening.

    please help

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: VBA code in Excel effecting other other excel worksheet/ workbook

    Can you post your code - without knowing what you are doing it is hard to answer. Just post the code you feel is affecting the other workbooks i.e how you are restricting access to sheets in the main workbook based on user login details.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  3. #3
    Registered User
    Join Date
    12-21-2011
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: VBA code in Excel effecting other other excel worksheet/ workbook

    please find code attached



    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    For Each sh In ActiveWorkbook.Sheets
    If sh.Name = "cover" Then
    Sheets("Summary").Visible = True 'Must have at least one sheet open
    GoTo nEXTsH
    End If
    Sheets(sh.Name).Visible = False 'Hide all other sheets on Close

    nEXTsH:
    Next sh
    End Sub

    Private Sub Workbook_Open()
    USN = Environ("USERNAME")

    'Expose all sheets for Administrator only.
    If USN = "dave" Then
    For Each sh In ActiveWorkbook.Sheets
    sh.Visible = True 'Expose sheet for Administrator only
    Next sh
    Exit Sub

    'Unhide Summary + users own sheet only
    Else
    For Each sh In ActiveWorkbook.Sheets
    If sh.Name = "Summary" Then
    Sheets("Summary").Visible = True
    ElseIf sh.Name = USN Then
    Sheets(USN).Visible = True
    Else: Sheets(sh.Name).Visible = False 'hides all other sheets
    End If
    Next sh
    End If

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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