VBA Validate file path

adam2010

New Member
Joined
Apr 19, 2010
Messages
4
I have created a spreadsheet at work I want it to remain in its original loaction and if any one copies it in to another folder I need a code so if its
is copied or moved the vba code prompts the user to only open the file from the original lacation and ends the application.

So realy a code to check Validate file path, where the location of the file is and if it dosn't match the correct original location then it closes.

hope some on can help

thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try this in the ThisWorkbook module (in the VBE double click ThisWorkbook and paste in the code). Change the path to suit.

Code:
Private Sub Workbook_Open()
If ThisWorkbook.Path <> "C:\Test" Then
    MsgBox "This workbook must be kept in C:\Test", vbExclamation
    ThisWorkbook.Close savechanges:=False
End If
End Sub
 
Upvote 0
thats nearly it.

Say the original file is C:\calculator\clculator.exl

and some one has copied the file an moved it to another location
it would not open because the original file location is C:\calculator\clculator.exl

that code worked but closed the spreadsheet in the original location


thanks alot for you help

adam
 
Upvote 0
Hmm. That didn't happen for me. I saved the file in c:\test, closed it and reopened it and it opened fine. I then moved it to the Desktop, tried opening and got the message and the file closed.
 
Upvote 0
Iv got it working great exactly what I wanted..... thank you
this is going to help me solve a lot of problems

regards

Adam
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

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