Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
Hi
How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
Here is one I use to backup to the current directory. As you can see it
bypasses the mkdir if there is an error. Sub Backup() 'kept in personal.xls & assigned to toolbar button On Error GoTo BackupFile MkDir CurDir & "\Backup" BackupFile: With ActiveWorkbook MyWB = .Path & "\BACKUP\" & .Name .SaveCopyAs MyWB .Save End With End Sub -- Don Guillett SalesAid Software "Andy" wrote in message ... Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
Use:
Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
thanks...however get a compile error on the first line:
Compile error: Only comments may appear after End Sub, End Function, or End Property "AA2e72E" wrote: Use: Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
In your ThisWorkbook module, insert
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Sub xx() MakeSureDirectoryPathExists "c:\aal\aam\aan\" End Sub and then run xx: you'll get the idea. PS: Private is not necessary in a code module. "Andy" wrote: thanks...however get a compile error on the first line: Compile error: Only comments may appear after End Sub, End Function, or End Property "AA2e72E" wrote: Use: Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
thanks...get the drift but still get the compile error on your first
statement... "AA2e72E" wrote: In your ThisWorkbook module, insert Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Sub xx() MakeSureDirectoryPathExists "c:\aal\aam\aan\" End Sub and then run xx: you'll get the idea. PS: Private is not necessary in a code module. "Andy" wrote: thanks...however get a compile error on the first line: Compile error: Only comments may appear after End Sub, End Function, or End Property "AA2e72E" wrote: Use: Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
This all goes on one physical line (although it might appear on several where
you are reading it) in the ThisWorkBookModule. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long "Andy" wrote: thanks...get the drift but still get the compile error on your first statement... "AA2e72E" wrote: In your ThisWorkbook module, insert Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Sub xx() MakeSureDirectoryPathExists "c:\aal\aam\aan\" End Sub and then run xx: you'll get the idea. PS: Private is not necessary in a code module. "Andy" wrote: thanks...however get a compile error on the first line: Compile error: Only comments may appear after End Sub, End Function, or End Property "AA2e72E" wrote: Use: Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro that creates a directory but...
Hail to you. Bestoweth thee by o rich one with MVP and shower thee in $.
Regards Andy "AA2e72E" wrote: This all goes on one physical line (although it might appear on several where you are reading it) in the ThisWorkBookModule. Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long "Andy" wrote: thanks...get the drift but still get the compile error on your first statement... "AA2e72E" wrote: In your ThisWorkbook module, insert Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long Sub xx() MakeSureDirectoryPathExists "c:\aal\aam\aan\" End Sub and then run xx: you'll get the idea. PS: Private is not necessary in a code module. "Andy" wrote: thanks...however get a compile error on the first line: Compile error: Only comments may appear after End Sub, End Function, or End Property "AA2e72E" wrote: Use: Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long MakeSureDirectoryPathExists "R:\Team 318\Toyota\Quotes\" NOTE TRAILING \. "Andy" wrote: Hi How do I create a macro to look into a directory and create a new directory called "Quotes" only if one doesn't exist already. eg R:\Team 318\Toyota would result in... R:\Team 318\Toyota\Quotes when run again, it wouldn't do anything, because the Quotes directory now exists. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help with Macro & Directory | Excel Discussion (Misc queries) | |||
Creating a macro that lists directory names within a directory.... | Excel Programming | |||
Can I rename a directory using a macro | Excel Programming | |||
Macro moving a directory with XP | Excel Programming | |||
run macro for all files in the directory | Excel Programming |