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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #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.

  4. #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.

  5. #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.

  6. #5
    JustCallMeAl
    Guest

    Re: Oh yeah. Duh. But...

    Gotta remember that Len function! Great little tool!

  7. #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.

  8. #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>

  9. #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!)

  10. #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

  11. #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.

  12. #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.

  13. #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.

  14. #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

  15. #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
  •