MsgBox auto populate problem

alhbeu

New Member
Joined
Jan 19, 2011
Messages
22
I have this code which autosaves a file to a certain location, however it automatically saves it with today's date
Dim filename As String
Dim location As String
Save = MsgBox("EXPORT?", vbYesNo, "EXPORT")
If Save = vbYes Then
filename = "sample name" & Format(Date, "yyyy_mm_dd") & "_EMEA.csv"

However it actually needs to be saved with the last Friday's date. How can I change it so I can either enter just the date part of the name into the message box, or just to manually enter in the name of the file each time??

Any help would be greatly appreciated!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Sub Test()

    Dim filename As String
    Dim location As String, i As Integer
    
    Select Case Format(Date, "ddd")
        Case "Sun"
            i = 2
        Case "Mon"
            i = 3
        Case "Tue"
            i = 4
        Case "Wed"
            i = 5
        Case "Thu"
            i = 6
        Case "Fri"   'change i to 0 if you want to show today's date if it is Friday
            i = 7
        Case "Sat"
            i = 1
    End Select
    
    Save = MsgBox("EXPORT?", vbYesNo, "EXPORT")
    If Save = vbYes Then
    filename = "sample name" & Format(Date - i, "yyyy_mm_dd") & "_EMEA.csv"
 
Upvote 0
Hi,

Try:

Code:
    Dim filename As String
    Dim location As String
    Dim x As Integer

    Save = MsgBox("EXPORT?", vbYesNo, "EXPORT")
    If Save = vbYes Then
        x = Weekday(Date)
        If x = 7 Then
            lfDate = Date - 1
        Else
            lfDate = Date - 1 - x
        End If
        
        filename = "sample name" & Format(lfDate, "yyyy_mm_dd") & "_EMEA.csv"
        ActiveWorkbook.SaveAs filename
    End If
 
Upvote 0
The file is run on Tuesdays, and the date needs to be for the Friday before - will the numbers assigned to the days work in this case?
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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