Solved

Avariation on current Macro to save file

Posted on 2014-09-15
5
148 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 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