PC Review


Reply
Thread Tools Rate Thread

Create Folder Using VBA

 
 
DoooWhat
Guest
Posts: n/a
 
      21st Sep 2007
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 With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      21st Sep 2007
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


 
Reply With Quote
 
=?Utf-8?B?RmFyaGFk?=
Guest
Posts: n/a
 
      21st Sep 2007
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
Tools>References

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
>
>

 
Reply With Quote
 
DoooWhat
Guest
Posts: n/a
 
      21st Sep 2007
Thanks so much! That worked perfectly.

Kevin

 
Reply With Quote
 
DoooWhat
Guest
Posts: n/a
 
      21st Sep 2007
JW's worked, so I didn't attempt the other solution. I appreciate
everybody's input.

Kevin

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      21st Sep 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solution to: Can't create file:.xls. Right click folder you want to create the file in and then click properties on the shortcut menu to check your permissions on this folder Ky_fanatic Microsoft Outlook Discussion 1 8th Dec 2006 06:15 PM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k Microsoft Excel Programming 6 11th Aug 2006 08:41 PM
When I try to open/save .rtf attachment I get the messages ?Can't create file. Right-click the folder you want to create item in and then click on the shortcut menu to check your permissions for the folder.? Nie Geweune via AdminLife Microsoft Outlook Installation 2 28th Jun 2006 05:07 PM
Create a search folder to look at all emails in one folder and selected criteria in other folders phil.whitacre@cox.net Microsoft Outlook 1 10th Apr 2006 09:40 AM
Unable to create the folder,'New Folder'.The drive cannot find the sector requested. =?Utf-8?B?aG9tZWUyMDEw?= Windows XP Help 3 2nd Jan 2004 10:06 PM


Features
 

Advertising
 

Newsgroups
 


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