用filesystemobject,方法如下:
dim Fso as object
Set Fso = CreateObject("Scripting.FileSystemObject")
Fso.CreateFolder ("foldname")
注意路径。

解决方案 »

  1.   

    to :cngxylyh(olo) 
       Scripting对象好像移到别的机子上容易出错。我推荐下面的方法:
    MkDir 语句
          创建一个新的目录或文件夹。
    语法
           MkDir path
       必要的 path 参数是用来指定所要创建的目录或文件夹的字符串表达式。path 可以包含驱动器。如果没有指定驱动器,则 MkDir 会在当前驱动器上创建新的目录或文件夹。
      

  2.   

    我用这种方法生成的程序在多台机器上运行通过。臭名远扬的I LOVE YOU病毒也是使用这种方法。
    当然Mkdir也可以创建一个新目录,但如果创建了一个同名的目录的话,就会造成程序出错而退出。用SCRIPTING就不会。
    如果真要用MKDIR的话就这样:
    if dir(path)="" then mkdir path
      

  3.   

    Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As LongDim attribut As SECURITY_ATTRIBUTES
    attribut.nLength = Len(attribut)
    attribut.lpSecurityDescriptor = &O0
    attribut.bInheritHandle = False
       Dim counter As Long
       Dim tnew As String
       Dim onew As String
       Dim i As Long
       Dim lnew As Long
       Dim tx As String
       Dim mi As String
       Dim minstra As Long
       Dim a As String
       a = InputBox("请输入要创建的文件夹名", "创建文件夹名")
       counter = 0
       If Right(a, 1) <> "\" Then
       a = a & "\"
       End If
       lnew = Len(a)
       For i = 1 To lnew
         tx = Left(a, i)
         If Len(tx) > 3 Then
          mi = Right(tx, 1)
          If mi = "\" Then
          Call CreateDirectory(tx, attribut)
          End If
         End If
        Next i
    End Sub
      

  4.   

    我是VB初学者,但我用过dir("path")在当前目录下建立子目录.
    也可以用文件系统对像.