?
Solved

Avariation on current Macro to save file

Posted on 2014-09-15
5
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
johnb25 earned 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

762 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