Consulting

Results 1 to 4 of 4

Thread: Using VBA to change File Folder Properties

  1. #1

    Using VBA to change File Folder Properties

    So I am trying to select a folder and have VBA toggle the read only option on that folder. I am at a loss at the moment, probably brain lock. Any constructive help would be appreciated as I am relatively new to VBA functionality of this level.

    Public Function ChangeReadOnly()
    Dim oFSO
    Dim oFolder
    Dim oFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder("\myPath\targetFolder")


    For Each oFile In oFolder
    FileAtt = VBA.GetAttr(oFile.Path)
    If FileAtt And vbReadOnly Then
    Call VBA.SetAttr(oFile.Path, FileAtt = Not (vbReadOnly))
    End If
    End Function

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Thank you. I was poking around the resource you provided. It seems that the read only attribute can't be toggled. I can try and set it as vbNormal. As long as this is a possibility and I'm not chasing ghosts, I will keep working. Anymore input would be very welcome.

    Edit: Great information in that link for file manipulation

    I have found: set the vbReadOnly to 0 and it toggles the attribute off

    example: SetAttr "C:\myPath\myDoc.docx", vbReadOnly = 0

    However I can't seem to apply this to a File Folder. Not sure if anyone has information on that specifically.
    Last edited by Coleman34; 08-26-2014 at 08:48 AM.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    To make a folder - G:\OF- (16) hidden (18)

    Sub M_snb()
       CreateObject("scripting.filesystemobject").getfolder("G:\OF").Attributes = 18
    End Sub

Posting Permissions

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