Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Changing File Attributes (Excel/VBA in 97 and >)

    Hi Folks

    Can I change the attribute of a file via VBA in Excel 97 and greater?

    I am writing an application that needs to move and save files on a network location, and it fails because some of the files it moves are Read-Only and the message comes up to confirm the move.

    I want to change the attribute before moving the file to say Normal, and then change it again after the move to what it was before.

    I know that I can use SendKeys to dismiss the dialog, or set display alerts to False and things like that, but I would like to change the attribute, if I can. This will impact another application as well.

    Thanks

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Changing File Attributes (Excel/VBA in 97 and >)

    Hi Wassim,
    Yes, if you use the FileSystem object, you can use GetAttr to store the current attributes and setattr to change them (in your example to vbNormal or 0) and then change them back if necessary.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Changing File Attributes (Excel/VBA in 97 and >)

    Rory

    Thanks, this is what I was looking for, but could not find in the OLH. Is this topic in the OLH or do I have to reinstall the OLH again <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Changing File Attributes (Excel/VBA in 97 and >)

    It is in mine but then I have a reference set to the MS Scripting Runtime which probably helps! (I'm also running WinXP and I know that the OLH on my Win2K system at work is a little temperamental!)
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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