Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: VBA Changing File to Read Only

  1. #1
    New Member
    Join Date
    Jul 2012
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Changing File to Read Only

    I am trying to use code in a VBA macro to change my file to a read-only file at the end of the macro after I've done a few other things to the file. I'm using this line of code:

    ActiveWorkbook.ChangeFileAccess xlReadOnly

    This code does in fact change the file to read-only. After the macro finishes I see "Read-Only" in the title of the file. However, when I close the file and re-open it the file is no longer read only.

    I've tried changing the code to this:

    ActiveWorkbook.ChangeFileAccess xlReadOnly
    ActiveWorkbook.Save

    But that doesn't work because it tells me I can't save the file after it's been converted to read-only.

    Any ideas?

    Thanks,

    JK

  2. #2
    MrExcel MVP
    Moderator
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    47,402
    Post Thanks / Like
    Mentioned
    37 Post(s)
    Tagged
    7 Thread(s)

    Default Re: VBA Changing File to Read Only

    I think you need to save it, and then change the attributes (probably from VBA code external to the file itself?).
    See here: MS Excel: SETATTR Function (VBA)
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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