Search code examples
vbaexcelvbscriptfilesystemobject

Make directory in VBscript relative to workbook running the macro


I'm using the following to create a folder:

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Create a new folder
oFSO.CreateFolder "C:\MyFolder"

But I'd like the folder location to be in the same place as the excel workbook running the code.


Solution

  • You can use

    ThisWorkbook.Path
    

    To return the path of the current workbook.

    Something like this:

    Dim oFSO As Object
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    oFSO.CreateFolder ThisWorkbook.Path & "\MyFolder"