PDA

View Full Version : Problem with MkDir



jsabo
10-04-2016, 11:13 AM
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.

offthelip
10-04-2016, 11:20 AM
yes I think you need to add
Microsoft forms 2.0 object library

jsabo
10-04-2016, 11:23 AM
Done. Still having the issue however.

offthelip
10-04-2016, 11:34 AM
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:

Dname1 = strDirectory & "\" & monm
If (Dir(Dname1, vbDirectory) = "") Then
MkDir (Dname1)
End If

the two variables are just a directory and a filename

Kenneth Hobs
10-04-2016, 12:41 PM
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