VBS to save file with name and yesterday's date

DDT~123

Board Regular
Joined
May 31, 2012
Messages
220
Not sure if this fits the Excel forum, but here goes...

I have the below script which creates a txt file but am needing for it to add yesterday's date to the end of the filename.
Example: "My Saved Report 2017-10-26.txt" (if today's date is October 27, 2017)


Code:
'LANGUAGE=ENU
'SERVERNAME=xx.xx.xx.xx
Public Sub Main()

On Error Resume Next
cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports("Historical\Designer\MultiSkill Daily")
If Info Is Nothing Then
If cvsSrv.Interactive Then
MsgBox "The report Historical\Designer\Multiskill Interval was not found on ACD 1.", vbCritical Or vbOKOnly, "Avaya CMS Supervisor"
Else
Set Log = CreateObject("ACSERR.cvsLog") 
Log.AutoLogWrite "The report Historical\Designer\Multiskill Interval was not found on ACD 1."
Set Log = Nothing
End If
Else
b = cvsSrv.Reports.CreateReport(Info,Rep)
If b Then
Rep.Window.Top = 1245
Rep.Window.Left = 20265
Rep.Window.Width = 22335
Rep.Window.Height = 9660  
Rep.SetProperty "Splits/Skills","152"      
Rep.SetProperty "Dates","-1"
b = Rep.ExportData("S:\Call Center\WFM Reporting\ScriptKeeper\Data Warehouse\Script Output\My Saved Report.txt", 9, 0, True, True, True)
Rep.Quit
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
End If
End If
Set Info = Nothing
'## cvs_cmd_end

End Sub

Thank you in advance for your help :)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You can use the VBA Date statement, which returns the current system date.

For example,
Rich (BB code):
b = Rep.ExportData("S:\Call Center\WFM Reporting\ScriptKeeper\Data Warehouse\Script Output\My Saved Report " & Date & ".txt"
, 9, 0, True, True, True)
should work.

If you'd like to format the date differently, you can use the Format statement. Like,

Rich (BB code):
Format (Date, "yyyymmdd")

which returns "20171027" today. Otherwise, it returns "10/27/2017".
 
Upvote 0
Since you want yesterday's date try

Code:
DateName = DateAdd("d",-1,Format(Date, "yyyy-mm-dd"))
[COLOR=#333333]b = Rep.ExportData("S:\Call Center\WFM Reporting\ScriptKeeper\Data Warehouse\Script Output\[U]My Saved Report " & DateName & ".txt"[/U], 9, 0, True, True, True)[/COLOR]
 
Upvote 0
Thanks guys!

The above suggestions didn't work but was able to find the code online.

Declared the following variable:
sDate = Year(Now()) & Right("0" & Month(now()), 2) & Right("00" & Day(Now()-1), 2)

line with code:
b = Rep.ExportData("S:\Call Center\WFM Reporting\ScriptKeeper\Data Warehouse\Script Output"&sDate &" - My Saved Report"&".txt", 9, 0, True, True, True)
 
Upvote 0

Forum statistics

Threads
1,223,789
Messages
6,174,571
Members
452,573
Latest member
Cpiet

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