Solved

Avariation on current Macro to save file

Posted on 2014-09-15
5
143 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
Comment Utility
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
Comment Utility
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
Comment Utility
Has this tested ok?
0
 

Author Comment

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

Author Closing Comment

by:Jagwarman
Comment Utility
Brilliant piece of work thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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 in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

728 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

10 Experts available now in Live!

Get 1:1 Help Now