help: Restrict access to Excel files

thunder_anger

Board Regular
Joined
Sep 27, 2009
Messages
206
Dear all

after i worked hard on my file
i want the file to open just in one computer and if copied to another computer it won't work

is that Possible?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
thunder_anger,

VoG, thank you.


Try VoG's suggestiong.

We are looking for something with your personal information:

Try:
Environ("USERPROFILE")
 
Upvote 0
thunder_anger,

Open a NEW workbook.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. And, paste the copied code into VBAProject, Microsoft Excel Objects, ThisWorkbook (on the right pane) by pressing the keys CTRL + V
5. Press the keys ALT + Q to exit the Editor, and return to Excel


Code:
Private Sub Workbook_Open()

If Environ("computername") <> "Thunder" Then
  
  Application.DisplayAlerts = False
  
  ThisWorkbook.Close
  
  Application.DisplayAlerts = True
  
End If


Then save the new workbook, Save As, a macro enabeled workbook with a file extension .xlsm


You should be able to open the workbook, on your computer, without a problem.


Then, copy this new workbook to a USB drive, etc., and ask someone in your department to try to open the workbook on their computer.
 
Last edited:
Upvote 0
thunder_anger,

On a NEW workbook, the Workbook_Open Even is already used?


Can we see the code?

If posting VBA code, please use Code Tags, see below in my Signature block: If posting VBA code, please use Code Tags - like this
 
Upvote 0
Hi VoG, Thunder anger

thank u for sharing such amezing informtion. can u explain.
what is Environ ? and is it possible if i login in PC with username & password, i will get
both using this function ? or any other vb code to find this
 
Upvote 0
Hi VoG, Thunder anger

thank u for sharing such amezing informtion. can u explain.
what is Environ ? and is it possible if i login in PC with username & password, i will get
both using this function ? or any other vb code to find this

Try runnning this

Code:
Sub env()
Dim i As Long
Sheets.Add
For i = 1 To 56
    Cells(i, 1).Value = Environ(i)
Next i
Columns("A").AutoFit
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,938
Latest member
babeneker

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