PDA

View Full Version : Validate startup path



mbrwny20
12-14-2008, 10:42 AM
Hello,

I'd like to insure that an authorized workbook on a network drive is the one being opened. Sometimes people will copy a workbook from the network to their desktop or their mydocuments folder, and now if I update information they will no longer have the current version.

This what I have tested today;

Sub Auto_Open()
If Application.StartupPath <> "c:\" & ThisWorkbook.Name & ".xls" Then
MsgBox ("you have opened this workbook in an invalid location.")
ThisWorkbook.Close
End If

End Sub

However, the startuppath is not what I desire. Should I be looking at workbook.fullname and then parse the path minus the workbook name to see if it has been opened from the desired directory.

Thank you

mdmackillop
12-14-2008, 11:05 AM
Sub TestOpen()
Dim Correct As String
Correct = "S:\Server\MyFolder\"
If Split(ActiveWorkbook.FullName, ActiveWorkbook.Name)(0) <> Correct Then
MsgBox "Please open from " & Correct
End If

End Sub

mbrwny20
12-14-2008, 12:57 PM
Thanks mdmack, I think that is the general diection I was headed in, but it was not as clean and concise.