Results 1 to 14 of 14
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CreateFolder macro?

    I need a Word2000 macro that will create a directory named "h:mso2000".

    Thanks in advance!

  2. #2
    JustCallMeAl
    Guest

    Re: CreateFolder macro?

    The entire macro consists of one line:

    <pre>mkdir "h:mso2000"</pre>


    So if you want an entire macro, with the name, it would consist of:

    <pre>Sub MakeMyDirectory()

    mkdir "h:mso2000"

    End Sub</pre>


    That's all.

  3. #3
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Oh yeah. Duh. But...

    I shoulda known that. How do I add a "mkdir if not exist" ? If the macro is run again, I get an error.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts

    Re: Oh yeah. Duh. But...

    Something along the lines of:

    <pre>If Len(Dir("h:mso2000")) Then
    MsgBox "Directory already exists."
    Exit Sub
    End If
    </pre>

    should do.

  5. #5
    JustCallMeAl
    Guest

    Re: Oh yeah. Duh. But...

    Gotta remember that Len function! Great little tool!

  6. #6
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting a runtime error

    Basically, I want the directory to be created if one does not exist. If one does exist, then nothing should happen (ie transparent to the user). Here is what I am trying:
    Sub Create2000Directory()
    '
    ' Create2000Directory Macro
    ' Macro created 5/24/2001 by W2KUSER
    '
    MkDir "h:mso2000"
    If Len(Dir("h:mso2000")) Then
    MsgBox "Directory already exists."
    Exit Sub
    End If
    End Sub

    When I run this the first time, I get the directory. When I run it the second time, I get a run-time error 75 Path/fil access error.

  7. #7
    JustCallMeAl
    Guest

    Re: Getting a runtime error

    The order in the macro is not correct.

    Try this:

    <pre>Sub Create2000Directory()
    '
    ' Create2000Directory Macro
    ' Macro created 5/24/2001 by W2KUSER
    '

    If Len(Dir("h:mso2000")) Then
    MsgBox "Directory already exists."
    Exit Sub
    End If

    MkDir "h:mso2000"

    End Sub
    </pre>


    Or better yet this:

    <pre>Sub Create2000Directory()
    '
    ' Create2000Directory Macro
    ' Macro created 5/24/2001 by W2KUSER
    '

    If Len(Dir("h:mso2000")) Then
    MsgBox "Directory already exists."
    Else
    MkDir "h:mso2000"
    End If

    End Sub
    </pre>


    You must test for existence of the directory before you attempt to create it. <img src=/S/joy.gif border=0 alt=joy width=23 height=23>

  8. #8
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Same problem...

    Tried your suggestion. Still get the same error if the directory exists. What am I doing wrong?

    (BTW I really appreciate your help!)

  9. #9
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Same problem...

    Hi Artf,

    Try:

    If Dir("C:ZZZ", vbDirectory) = "" Then MkDir "C:ZZZ"

    HTH,

    Chris

  10. #10
    JustCallMeAl
    Guest

    Re: Same problem...

    My mistake. Change this:

    If Len(Dir("h:mso2000")) Then

    To

    If Len(Dir("h:mso2000")) = 0 Then

    I tested it, and it works.

  11. #11
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    We have a weiner....

    It works perfectly. Nice and simple.
    Thanks to all who offered suggestions.

  12. #12
    New Lounger
    Join Date
    Jan 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still choking...

    That didn't seem to help. Maybe I'm doing something wrong. Chris Green's code did the trick.
    Thanks for your quick responses.

  13. #13
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Same problem...

    You realize you are saying if the length of the directory name is 0, then it exists. That doesn't quite make sense.

    FWIW

  14. #14
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Same problem...

    Try This:

    <pre>Sub Create2000Directory()
    ''' Create2000Directory Macro
    ''' Macro created 5/24/2001 by JustCallMeAl
    If Len(Dir("c:mso2000", vbDirectory)) > 0 Then
    MsgBox "Directory already exists."
    Exit Sub
    Else
    MkDir "c:mso2000"
    End If
    End Sub
    </pre>


    FWIW,

    TomG

Posting Permissions

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