PC Review


Reply
Thread Tools Rate Thread

Create a new folderand name it the previous month

 
 
ram
Guest
Posts: n/a
 
      16th Apr 2010
HI All,

I would like help with the following:

I would like to create a folder with the name of the current month less one.
Next, I would like to Save As the active file I’m working on with the name
Audit Report for current month less one. I would like to save this audit
report in the folder I just created above.

The code I’m trying to use is below. I think my problems are with the items
in blue

MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & Format(((Now) - 1), "mmm_yy")

ActiveWorkbook.SaveCopyAs
Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\Folder name from above
\AuditReport_" & Format(Now, "mmm_yy") & ".xls"

Thanks in advance for any help

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      16th Apr 2010
Dim NewFolderName as string

NewFoldername = "\\(longstringhere\" & format(date - day(date), "mmm-yy")

on error resume next 'in case it already exists
mkdir newfoldername
on error goto 0

activeworkbook.saveas filename:= newfoldername _
& "\auditreport_" & format(date-day(date),"mmm-yy") & ".xls"

===========
Date - Day(date)
will give the last day of the previous month.
(April 16, 2010 - 16 days is March 31, 2010)

Then just format that the way you want -- But I'd use a 4 digit year.

In fact, I'd use:

format(date - day(date), "yyyy-mm")

Then it would make it easier to sort in chronological order.

ram wrote:
>
> HI All,
>
> I would like help with the following:
>
> I would like to create a folder with the name of the current month less one.
> Next, I would like to Save As the active file I’m working on with the name
> Audit Report for current month less one. I would like to save this audit
> report in the folder I just created above.
>
> The code I’m trying to use is below. I think my problems are with the items
> in blue
>
> MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & Format(((Now) - 1), "mmm_yy")
>
> ActiveWorkbook.SaveCopyAs
> Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\Folder name from above
> \AuditReport_" & Format(Now, "mmm_yy") & ".xls"
>
> Thanks in advance for any help


--

Dave Peterson
 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      16th Apr 2010
I assume that the path all the way out to \MonthlyReport\ actually exists -
otherwise you have to create the sub-folders one at a time. Assuming that -
then here's how I'd probably do it

'early in the module
Dim newName As String

newName = Format(DateSerial(Year(Now()), Month(Now()) - 1, 1), "mmm-yy")
MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & newName
and later
ActiveWorkbook.SaveCopyAs _
Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\" & newName & _
Application.PathSeparator & newName & ".xls"


"ram" wrote:

> HI All,
>
> I would like help with the following:
>
> I would like to create a folder with the name of the current month less one.
> Next, I would like to Save As the active file I’m working on with the name
> Audit Report for current month less one. I would like to save this audit
> report in the folder I just created above.
>
> The code I’m trying to use is below. I think my problems are with the items
> in blue
>
> MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & Format(((Now) - 1), "mmm_yy")
>
> ActiveWorkbook.SaveCopyAs
> Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\Folder name from above
> \AuditReport_" & Format(Now, "mmm_yy") & ".xls"
>
> Thanks in advance for any help
>

 
Reply With Quote
 
ram
Guest
Posts: n/a
 
      16th Apr 2010
Thank you very much this is just what I needed

"JLatham" wrote:

> I assume that the path all the way out to \MonthlyReport\ actually exists -
> otherwise you have to create the sub-folders one at a time. Assuming that -
> then here's how I'd probably do it
>
> 'early in the module
> Dim newName As String
>
> newName = Format(DateSerial(Year(Now()), Month(Now()) - 1, 1), "mmm-yy")
> MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & newName
> and later
> ActiveWorkbook.SaveCopyAs _
> Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\" & newName & _
> Application.PathSeparator & newName & ".xls"
>
>
> "ram" wrote:
>
> > HI All,
> >
> > I would like help with the following:
> >
> > I would like to create a folder with the name of the current month less one.
> > Next, I would like to Save As the active file I’m working on with the name
> > Audit Report for current month less one. I would like to save this audit
> > report in the folder I just created above.
> >
> > The code I’m trying to use is below. I think my problems are with the items
> > in blue
> >
> > MkDir "\\NS-WARQVFS01\Audit\MonthlyReport\" & Format(((Now) - 1), "mmm_yy")
> >
> > ActiveWorkbook.SaveCopyAs
> > Filename:="\\NS-WARQVFS01\Audit\MonthlyReport\Folder name from above
> > \AuditReport_" & Format(Now, "mmm_yy") & ".xls"
> >
> > Thanks in advance for any help
> >

 
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
3-Color Scale Vlookup for Current Month/Previous/Pre-Previous NeoFax Microsoft Excel Misc 2 8th Jan 2010 07:04 PM
System Restore - previous day/previous month not happening RJM Windows XP Help 2 24th Oct 2006 06:37 PM
copy worksheet from previous month and rename to current month =?Utf-8?B?RGFuIEUu?= Microsoft Excel Programming 4 8th Dec 2005 09:40 PM
Re: print the previous month and next month small calendars in banner Jocelyn Fiorello [MVP - Outlook] Microsoft Outlook Calendar 1 1st Jul 2004 01:49 PM
Re: Print Monthly Calendar and have Date Navigator show previous month and following month Jocelyn Fiorello [MVP - Outlook] Microsoft Outlook Calendar 0 3rd Mar 2004 06:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:08 AM.