Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Macro & Directory Dave Excel Discussion (Misc queries) 1 June 20th 07 03:34 PM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Can I rename a directory using a macro Harvey[_3_] Excel Programming 2 February 6th 04 01:49 PM
Macro moving a directory with XP Peter Excel Programming 0 February 2nd 04 07:46 PM
run macro for all files in the directory igor Excel Programming 3 July 17th 03 03:48 PM


All times are GMT +1. The time now is 10:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"