Full Version: Test for file location with ThisWorkbook.Path (incomplete)
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
carolel
I want to prevent code in the Workbook_Open module running if the file is not in a specific location – i.e. if it’s been emailed to someone else or copied.
Is it possible to use ThisWorkbook.Path without specifying the whole path? The original file will be in one of various subfolders, so the first part will not change. I tried it using a wildcard but it doesn't work – something like this:
If ThisWorkbook.Path <> "K:\Shared\Reports\Sales\*" Then
Exit Sub
End If
(where * would be a monthly folder)
BTW this is not a security issue, I just don’t want recipients to see the user options msgbox when they open the file.
Thanks
Carole
StuKiel
Hi Carole,
You can do this using the Like operator:
If ThisWorkbook.Path Like "K:\Shared\Reports\Sales\*" Then
Stu.
carolel
Thanks Stu, great help sad.gif
arole
StuKiel
Glad you like it.
Good luck.
Stu.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.