Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Creating folders as per date.

Hi All,

I have created a macro and it generates a file from the data base and
it saves it on a particular location.

Now my problem is I want to save the files in the folders as per day.
I want a macro which should create a folder as I have mentioned below
automatically.

Zone (Zone will be available in the database.)
Year (If folder for year is not available it should generate
it automatically.)
Month (If folder for Month is not available it should
generate it automatically.)
Day (If folder for Day is not available it should
generate it automatically.)

File name will be combination of two strings and the user name.

For Ex: One file is generated with the name of TRS-BU-Jack.Smit.xls
on 13-Aug-09.
The above mentioned file should get generated in the folder of \
\ShareDrive\South Zone\2009\Aug\13-Aug-09\TRS-BU-Jack.Smit.xls

Regards
Heera Chavan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Creating folders as per date.

Folder = "\ShareDrive\"
On Error Resume Next
Folder = Folder & Zone & Aplication.PathSeparator
MkDir Folder
Folder = Folde & Year(Date) & Aplication.PathSeparator
MkDir Folder
Folder = Folde & Format(Date, "dd-mmm-yy") & Aplication.PathSeparator


--
__________________________________
HTH

Bob

"Heera" wrote in message
...
Hi All,

I have created a macro and it generates a file from the data base and
it saves it on a particular location.

Now my problem is I want to save the files in the folders as per day.
I want a macro which should create a folder as I have mentioned below
automatically.

Zone (Zone will be available in the database.)
Year (If folder for year is not available it should generate
it automatically.)
Month (If folder for Month is not available it should
generate it automatically.)
Day (If folder for Day is not available it should
generate it automatically.)

File name will be combination of two strings and the user name.

For Ex: One file is generated with the name of TRS-BU-Jack.Smit.xls
on 13-Aug-09.
The above mentioned file should get generated in the folder of \
\ShareDrive\South Zone\2009\Aug\13-Aug-09\TRS-BU-Jack.Smit.xls

Regards
Heera Chavan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Creating folders as per date.

Thank you Bob .........
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Creating folders as per date.

Try this code

Sub Savefile()

Set fs = CreateObject("Scripting.FileSystemObject")


'I put two double quotes in front of drive name
Folder = "\\ShareDrive\South Zone\"
'added for testing
Folder = "\\ssdnjusersrv1\jwarburg$\temp\"


FileDate = DateValue("13-Aug-09")
FileYear = Year(FileDate)
FileMonth = Format(FileDate, "MMM")
FileDay = Format(FileDate, "DD-MMM-YY")

'check if year folder exists
FName = Dir(Folder & FileYear, Attributes:=vbDirectory)
If FName = "" Then
'make new folder
Set YearFolder = fs.getfolder(Folder)
YearFolder.subfolders.Add FileYear
End If
'check if month folder exists
MonthFolderName = Folder & FileYear & "\" & FileMonth
FName = Dir(MonthFolderName, Attributes:=vbDirectory)
If FName = "" Then
Set MonthFolder = fs.getfolder(Folder & FileYear)
'make new folder
MonthFolder.subfolders.Add FileMonth
End If

'make new workbook and save
FName = "TRS-BU-Jack.Smit.xls"
Set bk = Workbooks.Add
bk.SaveAs Filename:=MonthFolderName & "\" & FName


End Sub


"Bob Phillips" wrote:

Folder = "\ShareDrive\"
On Error Resume Next
Folder = Folder & Zone & Aplication.PathSeparator
MkDir Folder
Folder = Folde & Year(Date) & Aplication.PathSeparator
MkDir Folder
Folder = Folde & Format(Date, "dd-mmm-yy") & Aplication.PathSeparator


--
__________________________________
HTH

Bob

"Heera" wrote in message
...
Hi All,

I have created a macro and it generates a file from the data base and
it saves it on a particular location.

Now my problem is I want to save the files in the folders as per day.
I want a macro which should create a folder as I have mentioned below
automatically.

Zone (Zone will be available in the database.)
Year (If folder for year is not available it should generate
it automatically.)
Month (If folder for Month is not available it should
generate it automatically.)
Day (If folder for Day is not available it should
generate it automatically.)

File name will be combination of two strings and the user name.

For Ex: One file is generated with the name of TRS-BU-Jack.Smit.xls
on 13-Aug-09.
The above mentioned file should get generated in the folder of \
\ShareDrive\South Zone\2009\Aug\13-Aug-09\TRS-BU-Jack.Smit.xls

Regards
Heera Chavan




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 on creating five folders David Shoemaker Excel Programming 1 November 12th 08 05:25 PM
Creating folders Peter[_61_] Excel Programming 5 March 20th 07 03:52 PM
Help with Creating folders on Save Alarmbloke Excel Discussion (Misc queries) 3 December 22nd 05 06:00 PM
Creating folders using VBA Fred Smith Excel Programming 2 May 8th 05 03:27 PM
Creating folders with VB Foss Excel Programming 2 February 24th 04 10:08 AM


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