Hi,
how do i write a macro to create a directory on my H: drive?
specificall, a folder called "data extractor"
thanks,
marc
Hi,
how do i write a macro to create a directory on my H: drive?
specificall, a folder called "data extractor"
thanks,
marc
Better yet....
how do you go about writing code for:
"if the directory called "data extractor" does not exist....create it....."
Hi Marc,
The simple code to do it is:
[vba]MkDir "H:\data extractor"[/vba]
I only say simple, as you may want to implement some error handling in case it already exists. Like:
[vba]Sub CreateDirectory()
On Error Resume Next
MkDir "H:\data extractor"
If Err.Number <> 0 Then MsgBox "Directory exists!"
On Error GoTo 0
End Sub[/vba]
Cheers,
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
You're too fast! Use the second option. It will accomplish what you're after!
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
Awesome!!! just Awesome!!
thank you!
You're welcome,
Now you get VBAX lesson 2, though!
See up the top of the thread, there's a Thread Tools menu? You can jump in there and mark your own threads solved. Another slick tool developed by our board coders!
Cheers,
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
This recursively creates directories - eg:
NW_MkDir("C:\The\Quick\Brown\Fox\Jumped\Over\The\Lazy\Dog")
Function NW_MkDir(NewFolderPath As String) As Boolean On Error Resume Next NW_PATH = Split(NewFolderPath, "\") For Each NW_FOLDER In NW_PATH NW_FOLDERS = NW_FOLDERS & "\" & NW_FOLDER ' MsgBox Mid(NW_FOLDERS, 2, 999) MkDir (Mid(NW_FOLDERS, 2, 999)) Next If Dir(NW_FOLDER, 16) = "" Then NW_MkDir = False Else: NW_MkDir = True End If End Function
Wrong timing (15 years), wrong method (recursion), wrong code.