Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Open a new Directory

Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Open a new Directory

Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Open a new Directory

Thanks Bob.........I actually meant "Create" a directory, not just "open"
one as I posted.......that's what happens when you get old <g..........

I suppose we also have to first determine if one exists by that
name........then, if not, Create a new one, if it does, then delete the
existing one and re-create it?..........

This stuff makes my head hurt..........

Vaya con Dios,
Chuck CABGx3



We're trying to decern what we want from what you sent anyway,
"Bob Phillips" wrote in message
...
Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open a new Directory

No need to leave VBA to do it. With On Error you don't need to check if it
exists either

On Error Resume Next
mkdir "C:\MyDir"
On Error goto 0


'
'
'

On Error Resume Next
Kill "C:\MyDir\*.*"
rmdir "C:\MyDir"
On Error goto 0

Assumes MyDir has no subdirectories.

--
Regards,
Tom Ogilvy


"CLR" wrote in message
...
Thanks Bob.........I actually meant "Create" a directory, not just "open"
one as I posted.......that's what happens when you get old <g..........

I suppose we also have to first determine if one exists by that
name........then, if not, Create a new one, if it does, then delete the
existing one and re-create it?..........

This stuff makes my head hurt..........

Vaya con Dios,
Chuck CABGx3



We're trying to decern what we want from what you sent anyway,
"Bob Phillips" wrote in message
...
Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete

it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Open a new Directory

Chuck,

Tm shows yhou how to make a directory in one statement, but if it does
exist, any files in it will remain. This may be what you want, but you
explanation suggests that you might wan t to clear it, so if this is the
case, this will do as you describe

Sub CLR()
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If FolderExists(sFolder) Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.deletefolder sFolder, force:=True
Set fso = Nothing
End If
MkDir sFolder

End Sub

'-----------------------------------------------------------------
Function FolderExists(Folder) As Boolean
'-----------------------------------------------------------------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
FolderExists = True
End If
End If
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Thanks Bob.........I actually meant "Create" a directory, not just "open"
one as I posted.......that's what happens when you get old <g..........

I suppose we also have to first determine if one exists by that
name........then, if not, Create a new one, if it does, then delete the
existing one and re-create it?..........

This stuff makes my head hurt..........

Vaya con Dios,
Chuck CABGx3



We're trying to decern what we want from what you sent anyway,
"Bob Phillips" wrote in message
...
Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete

it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Open a new Directory

Indeed that did it Tom.............thank you very kindly.........it works
now

Vaya con Dios,
Chuck, CABGx3



"Tom Ogilvy" wrote in message
...
No need to leave VBA to do it. With On Error you don't need to check if

it
exists either

On Error Resume Next
mkdir "C:\MyDir"
On Error goto 0


'
'
'

On Error Resume Next
Kill "C:\MyDir\*.*"
rmdir "C:\MyDir"
On Error goto 0

Assumes MyDir has no subdirectories.

--
Regards,
Tom Ogilvy


"CLR" wrote in message
...
Thanks Bob.........I actually meant "Create" a directory, not just

"open"
one as I posted.......that's what happens when you get old <g..........

I suppose we also have to first determine if one exists by that
name........then, if not, Create a new one, if it does, then delete the
existing one and re-create it?..........

This stuff makes my head hurt..........

Vaya con Dios,
Chuck CABGx3



We're trying to decern what we want from what you sent anyway,
"Bob Phillips" wrote in message
...
Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete

it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3











  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Open a new Directory

You perceived correctly Bob........that's exactly what we want and your
suggestion has been added and all is well now in "headache-land".

Thanks again ever so much to both you and Tom......

Vaya con Dios,
Chuck, CABGx3



"Bob Phillips" wrote in message
...
Chuck,

Tm shows yhou how to make a directory in one statement, but if it does
exist, any files in it will remain. This may be what you want, but you
explanation suggests that you might wan t to clear it, so if this is the
case, this will do as you describe

Sub CLR()
Dim sFolder
Dim fso
sFolder = "C:\NewDir"
If FolderExists(sFolder) Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.deletefolder sFolder, force:=True
Set fso = Nothing
End If
MkDir sFolder

End Sub

'-----------------------------------------------------------------
Function FolderExists(Folder) As Boolean
'-----------------------------------------------------------------
Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
FolderExists = True
End If
End If
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Thanks Bob.........I actually meant "Create" a directory, not just

"open"
one as I posted.......that's what happens when you get old <g..........

I suppose we also have to first determine if one exists by that
name........then, if not, Create a new one, if it does, then delete the
existing one and re-create it?..........

This stuff makes my head hurt..........

Vaya con Dios,
Chuck CABGx3



We're trying to decern what we want from what you sent anyway,
"Bob Phillips" wrote in message
...
Chuck,

What do you mean by open a directory?

To delete one, try

Dim FSO As Object

Set FSO = CreatObject("Scripting.FileSystemObject")
FSO.DeleteFolder "C:\MyDir" , force:=True



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CLR" wrote in message
...
Hi All..........

Would someone please be so kind as to tell me the code to open a new
directory on my C:\ drive?......and also please, the code to delete

it.

Thanking you very much.

Vaya con Dios,
Chuck, CABGx3











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
open all files in directory davethewelder Excel Discussion (Misc queries) 2 August 26th 08 02:01 PM
Open files in the same directory houghi Excel Discussion (Misc queries) 2 May 21st 07 03:56 PM
Open file in directory Mike Excel Programming 2 February 20th 04 08:02 PM
Open files in directory V. Roe Excel Programming 2 November 4th 03 07:45 PM
Open all files in a directory Tom Waters[_2_] Excel Programming 1 September 3rd 03 12:59 PM


All times are GMT +1. The time now is 03:47 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"