Test Access to Controlled Folder

a065tot

New Member
Joined
Jan 26, 2009
Messages
4
I have a VBA module for which the ultimate goal is to write an Excel file into a specific folder. That folder resides on a networked shared drive and has controlled access via the user's LAN ID.

So that the file is not lost in the event that a user is not authorized to read or write to the folder, I wanted to attempt the write of a test file. Failure would mean that the user is not authorized. Success would result in a subsequent Kill of the file.

No matter what I try and no matter what error trap I establish, the code will halt with an Error 1004 screen. I've tried On Error Goto, On Error Resume Next, Application.EnableEvents = False. All still end up with the Error 1004 when I attempt the test file write.

I've also (unsuccessfully) tried to work with testing the folder with the vbDirectory function since it has files already and the directory is visible even if the user has no permissions.

Searches on various sites have not turned up anything with keywords such as "protected", "permissions", "error 1004", and more. I may just be overlooking *the* keyword that will find something, but it remains elusive.

Any help would be greatly appreciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
So my best solution would be to deny access to the sub folder the file is kept in with network security
 
Upvote 0
Thanks you for a reply, Mole999. Access to the sub-folder is already in place. What I am attempting is to have the VBA code test access for the current user. This way, if the user is not authorized, then a message box would give them targeted text telling them that they do not have access. But everything I do errors out with '1004' and none of them will trap. It ends up halting the code execution.
 
Upvote 0
do you have any sheet protection in place, bearing in mind the 1004
 
Upvote 0
No, neither the worksheet nor the workbook have any protection. To help be sure that the file itself is not a problem, I changed the save location in the code to be a totally open-access folder (one without any ID access control.) It all worked perfectly.

I am beginnning to think that this is a functional design element (read "flaw") of VBA itself. A user with access to the folder has the code work fine. A user without access has the Error 1004 appear. What's a first for me is to have something bypass trapping. I have tried both On Error Resume Next and On Error Goto 'Label', but in both instances the Error 1004 appears and the code comes to a grinding halt with end or debug in the user's face.
 
Upvote 0
Thanks again, Mole999. While it still does not solve my issue, I absorbed a little new knowledge from the snippet. That never hurts. I'm going to let this go for now.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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