If then else

walt1122

Active Member
Joined
Jun 6, 2002
Messages
318
Hi All, need another favor. can you tell me how I should have this so it looks to see if the file is open and if the person's username matches?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False

If (Environ("UserName") = "e050308") Then
Workbooks("Convert NQ Pension from Tempe.xls").Close savechanges:=False
Else

do something else...

What I want is if the workbook was opened by "e050308" it must close without any changes. Or if it wasn't, then I don't get an error as I am now?

Is there some way to do an AND or OR as part of the code??

I have a half dozen or so usernames who can access the "Convert NQ Pension from Tempe.xls" and a couple of people who should not be allowed. I have a macro on auto_open that checks who they are and who can access the file but now I need to have the file close without saving ( it opens as read-only and must stay hidden) when then close the "primary" file. I don't even want them to know they are accessing this file so I don't even want the dialog box to open and ask if I want to save changes.

thanks

Walt
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Is it?

Code:
If (Environ("UserName") = "e050308") Then 
   On Error Resume Next
   With Workbooks("Convert NQ Pension from Tempe.xls")
      .Saved = True
      .Close
      On Error GoTo 0
   End With
Else
 
Upvote 0
Hi Andrew, heck it took me longer to write the description of the problem than it did for you to have the answer. Yes, it looks like it will perfectly.

thank you

Walt
 
Upvote 0

Forum statistics

Threads
1,203,027
Messages
6,053,120
Members
444,640
Latest member
Dramonzo

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