Create new directory

F

Francis Brown

Hello.

How to you create a directory named the same as a date stored in a cell.

say sheet MainPage has a date 25/10/2005 in cell C22.

How do you take this and make a Direcotry 22-10-2005 in C:/Datefile folder.

Thanks in advance.

Francis.
 
J

Jim Thomlinson

mkDir "C:\Datefile\" & format(sheets("MainPage").range("C22").Value, _
"yyyy-mm-dd")

Off the top of my head that should be close.
 
S

sebastienm

Francis,
you can use the mkdir statement. SOmething like (no tested):
'-----------------------------------
Dim s as string, path as string

path= "C:/Datefile/"

s=ThisWorksbook.sheets("MainPage").Range("C22").Text
s = replace(s, "/", "-") ' replace / with dash -

path= path & s ' <------ path string
makdir path
'------------------------------
Regards,
Sébastien
<http://www.ondemandanalysis.com>
 
J

Jim Thomlinson

Sebastien brings up an interesting point. If the value in C22 is a text
string then use his code to replace the slashes with dashes. If however, as I
had assumed, the value is a date then the replace will not work and my code
will... Depend on what you have...
 
B

Bob Phillips

Jim,

The text property of a range object is a text string, even if the value is a
date. It returns the cell as formatted. Your way is better though IMO as it
formats the date year first, which is better for sorting.

Bob
 
J

Jim Thomlinson

I didn't notice that Sebastien had used Text... I just assumed Value (which I
always use). I never use text for stuff like that because my end users like
to change formats and such on me. I guess that my end users are a little more
fiendish and clever than I would like... I will have to be more careful in
the future...

Nice catch Bob
 
B

Bob Phillips

It is quite a useful property to have up your sleeve Jim.

I still prefer your method :))

Bob
 
M

Maperalia

Sebastienm;
I wonder if you can help me to setup this macro. I want to create a
directory when I save as my file. My macro (see below) save as the file under
specific directory. However, I want to create a directory with the same
filename which is the description typed in the cell "C1" on the the sheet
"Test" and put my file under this new directory.
Could you please help me with this matter.
Thanks in advance.

Maperalia



'*** START MACRO *****
Sub SaveAs()
Dim WO As String

Set swApp = Application.SldWorks
Set swApp = GetObject("SldWorks.Application")
Set Part = swApp.ActiveDoc

WO = Worksheets("Test").Range("C1")
longstatus = Part.SaveAs3("C:\Table\Top\ " & WO & ".sldprt", 0, 2)
End Sub
'*** END MACRO *****
 
Top