+ Reply to Thread
Results 1 to 15 of 15

Macro should not work any other computer

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Sri Lanka
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    71

    Macro should not work any other computer

    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

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Macro should not work any other computer

    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:

    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
    That will ensure the user gets to see only the 'enable macros' sheet upon start.

    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")'
    Private Sub Workbook_Open()
    If Not InStr("username1,username2,username3", Environ("USERNAME")) > 0 Then Application.DisplayAlerts = False: ThisWorkbook.Close False
    End Sub
    Any username that is not in the 'allowed list', will result in the workbook auto-closing.
    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

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    Sri Lanka
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    71

    Re: Macro should not work any other computer

    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....

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Macro should not work any other computer

    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:
    dim sht as worksheet
    for each sht in thisworkbook.worksheets
    sht.visible = true
    next sht
    Try changing 'xlsheetveryhidden' into 'xlveryhidden', but it shouldn't matter.

  5. #5
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Macro should not work any other computer

    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.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro should not work any other computer

    Perhaps you could put something like this in the Open event.

    If Environ("HOME") <> "/Users/michaelerickson" Then ThisWorkbook.Close
    Excel is not secure. At all.
    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.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: Macro should not work any other computer


    Hi !

    Quote Originally Posted by mikerickson View Post
    Excel is not secure. At all.
    If you have truly sensitive data that you want protected, Excel is the wrong platform.
    I agree ! 1000% ‼

    This kind of "protection" is bypassed in few seconds …

  8. #8
    Registered User
    Join Date
    04-22-2013
    Location
    Philippines & Australia
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    73

    Re: Macro should not work any other computer

    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?

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro should not work any other computer


    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 !

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro should not work any other computer

    Duplicate …

  11. #11
    Registered User
    Join Date
    04-22-2013
    Location
    Philippines & Australia
    MS-Off Ver
    Excel 2016, Office 365
    Posts
    73

    Re: Macro should not work any other computer

    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

  12. #12
    Registered User
    Join Date
    02-19-2013
    Location
    Sri Lanka
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    71

    Re: Macro should not work any other computer

    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.

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Macro should not work any other computer

    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:

    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
    Regards,

    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

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Macro should not work any other computer

    @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

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro should not work any other computer


    Thanks Kyle123 !

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro does not work on different computer
    By kaffein in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2015, 03:46 PM
  2. Replies: 8
    Last Post: 12-15-2014, 04:36 PM
  3. Macro does not work when file is sent to another computer
    By brdstyle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2013, 01:51 AM
  4. The Macro for refreshing the pivot table does not work on a Mac computer - Need Help
    By prazad82 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2013, 01:01 AM
  5. why this macro doesn't work in my boss computer!?
    By matador_24 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-22-2011, 12:35 PM
  6. Macro won't work on another networked computer
    By n0v1c3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-15-2010, 02:35 AM
  7. Auto Filter on my home computer differs from my work computer.
    By Sbova0226 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-08-2009, 03:04 PM

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