|
Answer» I have a vbs SCRIPT to rename a file with the previous Sunday's date. This script works perfectly fine on my windows XP machine, however, I am getting a runtime error when trying to execute on a windows VISTA machine. I attached the error MESSAGE as well as the syntax of the script. Do I need to change a setting somewhere on my vista machine to get this work?
Dim dtDateBegWeek, fname1 dtDateBegWeek = date-datepart("w",date-1) fname1 = "aROsaleslast.xls_" & left(dtDateBegWeek,2) & mid(dtDateBegWeek,4,2) & right(dtDateBegWeek,2) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") fso.MoveFile "aROsaleslast.xls", fname1
[attachment deleted by admin]That says that your file isn't found. Is the file "aROsaleslast.xls" where it needs to be? How about using a full name? (such as "C:\myfolder\aROsaleslast.xls")The file is in the same folder with the script. I did try adding the full path, but still no luck. It works exactly as it is, on windows XP...just not on Vista!I've done a little more research...it seems that the syntax works on one computer, but not on another...both XP machines. The error is coming from the statement date-datepart("w",date-1).
So, my question is...how can I get this script to work? I need to rename my file with the previous Sunday date. I am not sure what day during the week it will run, as it is dependent on the user...but it should always have the previous Sunday date. Can anyone help me? Thanks much.Possibly the 2 different computers have different date format settings. ("Regional Settings")
See here
http://support.microsoft.com/kb/218964
Extract:
Quote The VBScript functions Now, Date, and Time rely on the Regional Settings in the computer for their formats. Regional Settings change, depending on the user who is logged on (or not logged on) to the computer. As a result, there is no way to guarantee that date and time formats will always be the same.
To ensure that your date and time formats are consistent, do one of the following:
* Use JScript, which does not rely on the regional settings for its date and time formats.
* Use functions other than Now, Date, and Time to display dates and times. Because the other date and time functions (for example, Day, Month, and Year) do not rely on regional settings, the formats do not change when different users log on to the computer. For example, the MyDate function always RETURNS the date in mm/dd/yyyy format:
Function MyDate() dteCurrent = Date()
dteDay = Day(dteCurrent) dteMonth = Month(dteCurrent) dteYear = Year(dteCurrent)
MyDate = dteMonth & "/" & dteDay & "/" & dteYear End Function
|