savepath change

AzureStoneDog

New Member
Joined
May 29, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Good morning. Here is what I currently have as code:

VBA Code:
Dim SavePath    As String
Dim SaveAs As String
Dim FileName As String
Dim sDate As String

SavePath = "\\..........\2020\"
FileName = "WC "
sDate = Format(Sheets("Monday").Range("B1"), "dd-mm-yyyy")
SaveAs = SavePath & FileName & sDate & ".xls"

I have folders labelled 01 Jan, 02 Feb and so on until 12 Dec (the number helps keep them in order), so after the 2020\ would be 2020\01 Jan\ for example. I'd like to set this so if the date of the range b1 is within a particular set of dates, it goes to the relevant monthly savepath.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the forum.
This might work
VBA Code:
Sub Example()
    
    Dim SavePath    As String
    Dim SaveAs      As String
    Dim FileName    As String
    Dim sDate       As String
    Dim dtDate      As Date
    
    SavePath = "\\..........\"
    FileName = "WC "
    dtDate = Sheets("Monday").Range("B1")
    
    sDate = Format(dtDate, "dd-mm-yyyy")
    SavePath = SavePath & Format(dtDate, "yyyy") & "\" & Format(dtDate, "mm") & " " & Format(dtDate, "mmm") & "\"
    SaveAs = SavePath & FileName & sDate & ".xls"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top