Environ nightmare

DThib

Active Member
Joined
Mar 19, 2010
Messages
464
Office Version
  1. 365
Platform
  1. Windows
My Inventory workbook has been working well for months. It has a code in the opening that checks for my login ID. It will show a worksheet for me to edit but not anyone else.
2 questions:
1) How do I add 2 more names so they may edit.
2) The other users are now getting the macro slowing to look for the Environ name and then it crashes.
It isn't supposed to and didn't befor last week.

Help!
Code for workbook open below:
Code:
Private Sub Workbook_Open()
 Dim UsedRange
  
  Worksheets("Inventory").Activate
  ActiveSheet.UsedRange.Select
  ActiveSheet.UsedRange.Copy
  Range("A2").Select
  Worksheets("Empty Boxes").Activate
  Range("A1").Select
  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
  Range("A2").Select
  Application.CutCopyMode = False
  Worksheets("Inventory").Activate
  Range("A1").Select
  Application.CutCopyMode = False
  Worksheets("Start").Activate
  Range("E3").Select
   Worksheets("Inventory").Visible = xlSheetVisible
  
    If Environ("username") = "dthibode" Then
    'testing - show the sheet
     Worksheets("Inventory").Visible = xlSheetVisible
     Else
    'standard user - completely hide sheet
     Worksheets("Inventory").Visible = xlSheetHidden
    End If
End Sub

Any ideas?:confused::confused::confused:
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Example (change the names to suit):

Code:
If Environ("username") = "dthibode" Or Environ("username") = "Person2" Or Environ("username") = "Person3" Then

I'm sorry i don't know the answer to your second question.
 
Upvote 0
Thanks, Andrew. I wanted t make sure the solution was what I thought.
The 2nd issue has me wondering what is happening. Does anyone else have an answer.
We are running Excel2003 and Windows XP sp3.0. The workbook sits on a server and is about 3.98mB large.
 
Upvote 0
As an aside, you might want to remove the Dim for the variable UsedRange as it's not used anywhere in the procedure. The UsedRange which is referenced in the procedure is a property of the worksheet and not the variable which is declared.

(You might be aware of that but it may confuse the next person who has to modify the code. I try to avoid naming variables after other Excel or VBA keywords or just that reason.)
 
Upvote 0
Thanks, Andrew. I wanted t make sure the solution was what I thought.
The 2nd issue has me wondering what is happening. Does anyone else have an answer.
We are running Excel2003 and Windows XP sp3.0. The workbook sits on a server and is about 3.98mB large.

Do your users get an error with Environ("UserName")?
 
Upvote 0
Yes Andrew, they do. The workbook opens and pauses in the middle of the code then throws the error for that comment. It did not before.

JackDanIce,
This was not a repost. This was a request for the 2nd question to be answered after Andrew had confirmed my first question. But thank you for your attention to detail.
Debbie
 
Upvote 0
As an aside, you might want to remove the Dim for the variable UsedRange as it's not used anywhere in the procedure. The UsedRange which is referenced in the procedure is a property of the worksheet and not the variable which is declared.

(You might be aware of that but it may confuse the next person who has to modify the code. I try to avoid naming variables after other Excel or VBA keywords or just that reason.)
Thanks, Ruddles
Useful information. I agree. No, I did not know that.
Andrew's answer was something I had tried but deleted because of the issue in Question 2. I meant no disrespect to him in my answer.

Debbie
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top