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.
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,939
Office Version
2019, 2016, 2013
Platform
Windows
So my best solution would be to deny access to the sub folder the file is kept in with network security
 

a065tot

New Member
Joined
Jan 26, 2009
Messages
4
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.
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,939
Office Version
2019, 2016, 2013
Platform
Windows
do you have any sheet protection in place, bearing in mind the 1004
 

a065tot

New Member
Joined
Jan 26, 2009
Messages
4
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.
 

a065tot

New Member
Joined
Jan 26, 2009
Messages
4
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.
 

Forum statistics

Threads
1,084,856
Messages
5,380,318
Members
401,664
Latest member
traveler84

Some videos you may like

This Week's Hot Topics

Top