VB Script

S

Steph

Hello. I would like to schedule a VB Script to run (via Windows Scheduler),
which will simply copy a file from one directory into another with the name
of the copied file as as a today timestamp. I am extremely new to VB
Script - can anyone help with the syntax? Thank you.
 
J

Jim Rech

This may help. Here is a VB script I use to copy my XLB backup files over
the current XLBs. This goes in a VBS file as you know.


dim FSO
dim Path

Path = "C:\Documents and Settings\jarech\Application Data\Microsoft\Excel\"
Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFile Path & "Excel11Bak.xlb", Path & "Excel11.xlb"
FSO.CopyFile Path & "Excel10Bak.xlb", Path & "Excel10.xlb"
FSO.CopyFile Path & "ExcelBak.xlb", Path & "Excel.xlb"

--
Jim
| Hello. I would like to schedule a VB Script to run (via Windows
Scheduler),
| which will simply copy a file from one directory into another with the
name
| of the copied file as as a today timestamp. I am extremely new to VB
| Script - can anyone help with the syntax? Thank you.
|
|
|
 
S

Steph

Thanks Jim. It worked perfectly. But I messed it up a bit by trying to
have the copied file named as today's timestamp:

Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile sExcelPath, CopytoPath & Format(Now, "yyyymmddhhmmss") & ".xls"

When I ran, I got an error: Variable is undefined: 'Format'
So I'm guessing I am mixing VBA with VBS. Any idea how I would rewrite this
in VBS syntax? Thanks!
 
S

Steph

Got it:

CStr(Year(Now)) & Right(00 & CStr(Month(Now)),2) & Right(00 &
CStr(Day(Now)),2) & Right(00 & CStr(Hour(Now)),2) & Right(00 &
CStr(Minute(Now)),2) & Right(00 & CStr(Second(Now)),2)

Format doesn't exist in VBS, so build your own!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top