Hi Friends
I need a help from you please.
one of excel document contain confidential information. So that, this file should not work any other computer except my computer. Is there any way to prevent run macro from other computer?
Thanks![]()
Hi Friends
I need a help from you please.
one of excel document contain confidential information. So that, this file should not work any other computer except my computer. Is there any way to prevent run macro from other computer?
Thanks![]()
Technically it's not possible as such, but you can 'protect' your sheet to a certain extend.
a) Protect your VBA code through Tools -> VBAProject Properties -> Protection
b) Set up a splash screen to force people to enable macros.
Name a sheet "splash" and have it say "Please enable content to continue"
Then, in your WORKBOOKcode area, add the following:
That will ensure the user gets to see only the 'enable macros' sheet upon start.![]()
Public ws As Worksheet, ac As Range Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim sht As Worksheet Application.ScreenUpdating = False Set ws = ActiveSheet Set ac = ActiveCell Worksheets("splash").Activate For Each sht In ThisWorkbook.Worksheets If Not sht.Name = "splash" Then sht.Visible = xlSheetVeryHidden Next sht End Sub Private Sub Workbook_AfterSave(ByVal Success As Boolean) Application.ScreenUpdating = False Dim sht As Worksheet For Each sht In ThisWorkbook.Worksheets sht.Visible = True Next sht ws.Activate ws.Range(ac).Activate Worksheets("splash").Visible = xlVeryHidden Application.ScreenUpdating = True End Sub
Then to prevent unwanted people to open put this also in the WORKBOOK code area:
Make sure you at least put your windows logon name in the part with 'username1,username2,username3' etc - this is where you put the windows login names of the people you want to have access. Not sure what yours exactly is, go to the immediate code area (control+G in the VBA area) and type 'debug.print environ("username")'
Any username that is not in the 'allowed list', will result in the workbook auto-closing.![]()
Private Sub Workbook_Open() If Not InStr("username1,username2,username3", Environ("USERNAME")) > 0 Then Application.DisplayAlerts = False: ThisWorkbook.Close False End Sub
Enjoy
ps, instead of blocking on username, you can also use Environ("COMPUTERNAME")
Last edited by JasperD; 07-19-2015 at 01:52 AM.
Please click the * below if this helps
Hi JasperD,
Thank you very much for your quick respond.
Please solve this issue.
When I click Save button, bellow code is highlighted as an error
sht.Visible = xlSheetVeryHidden
And one more think is now i coudn't find the perticular sheet.
How can I get it back?
Thanks....![]()
did you create a sheet called 'splash' ?
What the code does is hide all sheets upon save and if there's a sheet called 'splash', the code shouldn't error
Unhide all via:
Try changing 'xlsheetveryhidden' into 'xlveryhidden', but it shouldn't matter.![]()
dim sht as worksheet for each sht in thisworkbook.worksheets sht.visible = true next sht
Wouldn't it be possible to just add a password code snippet in the beginning of the code and then protect the code with the built in password protection. The first password could be read from another Excel file that you keep on your computer only.
<----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left
If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.
Perhaps you could put something like this in the Open event.
Excel is not secure. At all.![]()
If Environ("HOME") <> "/Users/michaelerickson" Then ThisWorkbook.Close
If you have truly sensitive data that you want protected, Excel is the wrong platform.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
I have often read about the insecurities in Excel, but I am intrigued to know how if the VBA project is password protected that "This kind of "protection" is bypassed in few seconds …". I am not being smart, I would just like to know?
So many tricks around the net ! Either by code or simple manipulation …
Excel 2013 version is better protected but recently I saw a society sales on net a tool to break it !
So for very sensitive data, just avoid Excel !
Duplicate …
I had a similar need to yours and I got around it this way. I created a small txt file (F:\AuthorizedComputer.txt) and placed it on the computer that is authorized. Then at the start of the macro you wish to check if this computer is ok to proceed place the code in the attached macro. This is just a simple way to stop unauthorized running of the macro.
![]()
Dim Authorization Authorization = "F:\AuthorizedComputer.txt" FilePresent = Dir(Authorization) If FilePresent = "" Then Exit Sub
Thank you very much JasperD, Now It work. Perfect
Thank you mikerickson and Catman50.
I added your code too for further protection.
Thanks a lot for all.
Hi janagan,
Though Excel is not secure, just to answer your question you could check the machine name that the code is being opened from and if it's not equal to yours end it, which would be something like this:
Regards,![]()
Option Explicit Sub Macro1() Dim objWshNetwork As Object Set objWshNetwork = CreateObject("Wscript.Network") If objWshNetwork.computername <> "ABC123" Then '<= This would be your machine name MsgBox "The file is not permitted to be opened on this machine!!", vbCritical Set objWshNetwork = Nothing Exit Sub Else 'Run your macro as the file has been opened from your machine End If Set objWshNetwork = Nothing End Sub
Robert
____________________________________________
Please ensure you mark your thread as Solved once it is. Click here to see how
If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post
@Marc L, 2013 VBA protection is no better than earlier versions. I believe that the additional protection is related to Password to open and Encrypting the workbook
Thanks Kyle123 !
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks