Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Create Folder Using VBA

I would like to create a folder using the values in a specific cell on
a worksheet. Let's say, for instance, that the value of A1 is: C:
\Reports\2007-09-18

The 'Reports' directory MAY OR MAY NOT already have a '2007-09-18'
folder. I would like the code to be conditional, in that it will
create the folder if it does not exist, otherwise don't do anything.
Any help is much appreciated.

Thanks.

Kevin

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 638
Default Create Folder Using VBA

One way:
Sub foo()
Dim d As String
d = Range("A1").Text
If Dir(d, vbDirectory) < "" Then
MsgBox d & " already exists", , "Error"
Else
MkDir d
End If
End Sub

DoooWhat wrote:
I would like to create a folder using the values in a specific cell on
a worksheet. Let's say, for instance, that the value of A1 is: C:
\Reports\2007-09-18

The 'Reports' directory MAY OR MAY NOT already have a '2007-09-18'
folder. I would like the code to be conditional, in that it will
create the folder if it does not exist, otherwise don't do anything.
Any help is much appreciated.

Thanks.

Kevin


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Create Folder Using VBA

Thanks so much! That worked perfectly.

Kevin

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Create Folder Using VBA

JW's worked, so I didn't attempt the other solution. I appreciate
everybody's input.

Kevin

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 281
Default Create Folder Using VBA

Hi,

Try this:

Dim Fldr As Scripting.FileSystemObject
Set Fldr = New Scripting.FileSystemObject
If Fldr.FolderExists("C:\Reports\2007-09-18") Then
Else
Fldr.CreateFolder "C:\Reports\2007-09-18"
End If

make sure you have referred to MicroSoft Scripting Runtime from
ToolsReferences

Thanks,
--
Farhad Hodjat


"DoooWhat" wrote:

I would like to create a folder using the values in a specific cell on
a worksheet. Let's say, for instance, that the value of A1 is: C:
\Reports\2007-09-18

The 'Reports' directory MAY OR MAY NOT already have a '2007-09-18'
folder. I would like the code to be conditional, in that it will
create the folder if it does not exist, otherwise don't do anything.
Any help is much appreciated.

Thanks.

Kevin




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 947
Default Create Folder Using VBA

Just another option. If it exists, it will skip MkDir.

Sub Demo()
Const d As String = "C:\Reports\2007-09-18\"
On Error Resume Next
MkDir d
End Sub

--
HTH :)
Dana DeLouis


"DoooWhat" wrote in message
ups.com...
I would like to create a folder using the values in a specific cell on
a worksheet. Let's say, for instance, that the value of A1 is: C:
\Reports\2007-09-18

The 'Reports' directory MAY OR MAY NOT already have a '2007-09-18'
folder. I would like the code to be conditional, in that it will
create the folder if it does not exist, otherwise don't do anything.
Any help is much appreciated.

Thanks.

Kevin



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
Macro to create a new folder according to the month Dolphin Excel Discussion (Misc queries) 5 December 15th 06 01:31 PM
How to create a copy of a folder having five files in it, & rename Matthews Excel Worksheet Functions 1 November 7th 06 03:42 PM
create folder and save as runandrun Excel Discussion (Misc queries) 10 September 23rd 05 11:40 PM
How to create the hyperlink from Excel doc. to the folder Anton Excel Discussion (Misc queries) 4 September 6th 05 02:10 AM
How do I Create backup of excel file in other folder khalid Excel Discussion (Misc queries) 1 May 24th 05 11:01 AM


All times are GMT +1. The time now is 12:02 PM.

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

About Us

"It's about Microsoft Excel"