Solved

Avariation on current Macro to save file

Posted on 2014-09-15
5
147 Views
Last Modified: 2014-09-17
I use the below macro which was given to me by IrogSinta on EE,  to save files where the date and month change
In my current project I need to save files that are forward dated 3 days but I do not want to save with weekend dates. i.e. on Wed I need to save with Mondays date, Thurs with Tues and Friday with Wed.

 Could the below code be amended to do this.


Sub monthFolder()
    Dim sFilename As String
    Dim sPath As String
     
    sFilename = "myWorkbook.xls" 'Set filename
    sPath = "C:\rights\Mkt\Break\" 'Set base path
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\" 'Check for "\"
   
    sPath = sPath & Format(Date, "yyyy\\mm mmm\\")
   
    If Dir(sPath, vbDirectory) = "" Then 'If folder doesn't exist, create it
        Shell "cmd /c mkdir """ & sPath & """"
    End If
    ActiveWorkbook.SaveAs sPath & Format(Date, "mmddyyyy_") & sFilename
End Sub
0
Comment
Question by:Jagwarman
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
johnb25 earned 500 total points
ID: 40323477
Hi,

This should do it:
Sub monthFolder()
    Dim sFilename As String
    Dim sPath As String
     
    sFilename = "myWorkbook.xls" 'Set filename
    sPath = "C:\rights\Mkt\Break\" 'Set base path
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\" 'Check for "\"
    
    sPath = sPath & Format(WorksheetFunction.WorkDay(Now(), 3), "yyyy\\mm mmm\\")
   
    If Dir(sPath, vbDirectory) = "" Then 'If folder doesn't exist, create it
        Shell "cmd /c mkdir """ & sPath & """"
    End If
    
    ActiveWorkbook.SaveAs sPath & Format(WorksheetFunction.WorkDay(Now(), 3), "mmddyyyy_") & sFilename
End Sub

Open in new window


It moves the folder path forward 3 days also.

John
0
 

Author Comment

by:Jagwarman
ID: 40324737
thanks looks good John but I can't test it fully until tomorrow. Never the less I will accept it and give you the points now. regards
0
 
LVL 6

Expert Comment

by:johnb25
ID: 40326689
Has this tested ok?
0
 

Author Comment

by:Jagwarman
ID: 40327635
Sorry got caught on something else. This is brilliant many thanks John.
0
 

Author Closing Comment

by:Jagwarman
ID: 40327636
Brilliant piece of work thanks
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This collection of functions covers all the normal rounding methods of just about any numeric value.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now