+ Reply to Thread
Results 1 to 6 of 6

how to use VBA to dele files in the same folder or disk?

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Hongkong,PRC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Lightbulb how to use VBA to dele files in the same folder or disk?

    in our department, we have to avoid some files to be read by someone who have not the right to reaf the information. If he copy this files to his U disk or D disk, but he do not have the right to read(we have all the PC's information, we have use VBA to let those who have the rights to read the files.

    But for those illegal readers, we need to delete the files even they have change the file to read only. The following is VBA we use but could only dele the documents under relating path and files are not changed to read only.
    Could somebody help me to amend this VBA to delete all the files under the open files same path or same disk. Thanks you in advance.

    Please Login or Register  to view this content.
    Or someone could give me a VBA code to forbide someone to copy the sheets or contents in the files open. Thanks.
    Last edited by Cutter; 08-20-2012 at 07:54 AM. Reason: Added code tags

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: how to use VBA to dele files in the same folder or disk?

    Why not just put a password on the spreadsheet that means you need to type it in to even open the workbook?

    Or, even better, put them in a location that they don't have the permissions to view

  3. #3
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: how to use VBA to dele files in the same folder or disk?

    I'm not sure to have understood well but try with this change
    str = Dir(myfile & "\*.*", vbReadOnly)
    Last edited by patel45; 08-20-2012 at 08:52 AM.

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: how to use VBA to dele files in the same folder or disk?

    @ peter-chen

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

  5. #5
    Registered User
    Join Date
    08-20-2012
    Location
    Hongkong,PRC
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: how to use VBA to dele files in the same folder or disk?

    it could not dele the files under the folder if changing like that. Thanks

    ---------- Post added at 04:40 AM ---------- Previous post was at 04:39 AM ----------

    password could easily be exposed or un-locked.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: how to use VBA to dele files in the same folder or disk?

    Trying to use excel as a user access tool is fundamentally flawed. It is inherently too insecure, put the files in a location that the people who should not be able to see them cannot access them and use windows authentication to manage it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1