Share via

VBA - Create a HIDDEN folder

Anonymous
2017-12-15T15:45:41+00:00

Hello everyone,

I'm currently using some vba code to create a folder. This uses the MkDir function. See below:

Charts_Path = Application.ActiveWorkbook.Path & "\Charts"

If Dir(Charts_Path, vbDirectory) = "" Then MkDir Charts_Path

This does exactly what I want it to do. However, once I've created the folder I'd like to change its properties and hide it (Folder properties > Attributes > Hidden).

Any ideas?

Thanks,

Daniel

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-12-15T16:13:52+00:00

The following Sub will Hide or Show the folder depending on its current state

Sub Hide_Show_Folder()

    Dim objFSO As Object

    Dim objFolder As Object

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objFolder = objFSO.GetFolder(Application.ActiveWorkbook.Path & "\Charts")

    If objFolder.Attributes = objFolder.Attributes And 2 Then

        objFolder.Attributes = objFolder.Attributes Xor 2

    End If

    Set objFolder = Nothing

    Set objFSO = Nothing

End Sub

Was this answer helpful?

7 people found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-12-15T20:23:55+00:00

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-12-15T16:30:37+00:00

    Perfect! Thank you.

    Was this answer helpful?

    0 comments No comments