Workbook Security By Location

Jay Baker

New Member
Joined
Dec 9, 2003
Messages
15
I want to make sure that my workbooks aren't copied and opened on other computers. Notwithstanding the idea of "security" with an xls workbook (or lack thereof) :unsure: I'm trying to write a macro that will allow a workbook to check and see if a certain file exists on a hard disk to allow it to open. The code I have butchered :p is:

Option Explicit
Private Const LINK_PATH As String = "C:"
Private Const FILE_NAME As String = "Book1.xls"
Private Sub Workbook_Open()
Select Case GetValue(LINK_PATH, FILE_NAME)
Case "File Not Found"
GoTo CloseMe
Case "OK"
GoTo ExitHere
End Select
ExitHere:
Exit Sub
CloseMe:
ThisWorkbook.Close False
GoTo ExitHere
HandleErr:
MsgBox Err.Description
Resume ExitHere
End Sub

'======== REGULAR MODULE (OR WORKBOOK MODULE) ========

Public Function GetValue(LINK_PATH, FILE_NAME)

' Taken from John Walkenbach's web site:

' http://www.j-walk.com/ss/excel/eee/eee009.txt ,

' this function will read the value from a closed

' workbook.
' Retrieves a value from a closed workbook

Dim arg As String

' Make sure the file exists

If Right(LINK_PATH, 1) <> "" Then LINK_PATH = LINK_PATH & ""

If Dir(LINK_PATH & FILE_NAME) = "" Then

GetValue = "File Not Found"

If Dir(LINK_PATH & FILE_NAME) <> "" Then

GetValue = "OK"
Exit Function

End If
End If

' Execute an XLM macro

GetValue = ExecuteExcel4Macro(arg)
End Function

Where I have tried C:Book1.xls as the file to check and needless to say it doesn't work. :rolleyes:

This is stuff that I have tried to piece together from different posts, so if there is a completely different (read better) way to do this, please let me know.

Thanking in advance,
Jay
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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