Consulting

Results 1 to 5 of 5

Thread: Problem with MkDir

  1. #1
    VBAX Regular
    Joined
    Nov 2012
    Posts
    57
    Location

    Problem with MkDir

    I am trying to just test out making a directory if one does not exist. Here is a test code I am running:

    Sub mk_dir_basic()
    '
    ' mk_dir_basic Macro
    '
    
    
    '
    If Len(Dir("c:\TOTN\Excel\Examples", vbDirectory)) = 0 Then
       mkdir ("c:\TOTN\Excel\Examples")
    End If
    
    
    End Sub
    I get an error: "Compile Error: Wrong number of arguments or invalid property assignment". I have tried it with and without the parenthesis next to mkdir.

    What seems odd is that Visual Basic is not capitalizing mkdir to MkDir, as if it does not recognize it as a function? Is there a VBA reference I have to activate? Thanks.

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    yes I think you need to add
    Microsoft forms 2.0 object library

  3. #3
    VBAX Regular
    Joined
    Nov 2012
    Posts
    57
    Location
    Done. Still having the issue however.

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    It works for me and the references that I have got set are:
    Visual Basic for Applications
    Microsoft Excel 12.0 Object library
    OLE Automation
    Microsoft Office 12.0 Object library
    Microsoft forms 2.0 Object library

    The code I have got is:

    [VBA]Dname1 = strDirectory & "\" & monm
    If (Dir(Dname1, vbDirectory) = "") Then
    MkDir (Dname1)
    End If
    [/VBa]
    the two variables are just a directory and a filename

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Yes, you have a problem if mkdir is not being changed by intellisense.

    Of course mkdir fails if the previous paths do not exist. It only works for the last subfolder.

    This does it all in one line and creates all the paths, if the drive exists.
    Shell "cmd /c md " & """" & "c:\TOTN\Excel\Examples" & """", vbHide

Posting Permissions

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