+ Reply to Thread
Results 1 to 6 of 6

Change Read Only attribute on files in a folder

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Change Read Only attribute on files in a folder

    Hey there, I'm trying to set the read only attribute on all files in a folder. Yesterday I used SetAttr and it worked fine. I came in this morning and tested out my code again, and now it keeps giving me a "file not found" error, but nothing has changed between 5 o'clock last night and 8 this morning. Here's my code

    Please Login or Register  to view this content.
    What I'm doing is creating a simple interface that will allow me to update formulas in a folder full of workbooks. It sets read only as normal, opens them, unprotects the sheet, replaces the formula, protects the sheet, saves, closes, sets the file as read only, and moves on to the next file in the folder.

    My problem is it's now errorring out on the
    Please Login or Register  to view this content.
    line and saying "file not found." What am I doing wrong? This worked yesterday evening. Is there a different way to set this attribute? I've searched but haven't found anything useful

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Change Read Only attribute on files in a folder

    This means you don't have a file ending .xlsm in the folder W:\TOM\ERIC\New folder

    Add debug.print myfile to verify

    You can't set the attribute on the nonexistant file.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Change Read Only attribute on files in a folder

    Thanks for the reply, but I have 20 files in my folder, and all end in .xlsm. This worked 10 times in a row last night, nothing has changed since leaving the office and coming in this morning except the macro itself seems to be grumpy this morning

    EDIT: Also, if I comment out the 2 SetAttr lines in my code, and set the Read Only attribute of my files to normal by hand under the properties dialog, the code runs fine. This means the code IS finding the .xlsm files. There's something fishy with the SetAttr command.
    Last edited by VBA FTW; 04-05-2013 at 09:45 AM.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Change Read Only attribute on files in a folder

    Please Login or Register  to view this content.
    oughta do it
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Change Read Only attribute on files in a folder

    Thanks JP, you have solved my problem once again. Much appreciated sir

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Change Read Only attribute on files in a folder

    Glad someone could help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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