Home > Software engineering >  The purpose of the VBS used by CopyFile adding variable path problem
The purpose of the VBS used by CopyFile adding variable path problem

Time:12-22

This is a VBS according to excel template, copy to generate a new excel, and named after the time when the copy to the new generation of excel program, the following
 Option Explicit 
The Function action
Dim fso, myfile daystr, DSTR, fname
DSTR=FormatDateTime (Date)
DSTR fname="d: " + + ". XLS "
The Set of fso=CreateObject (" scripting. FileSystemObject ")
The Set MyFile=fso. GetFile (" d: \ ExcelExample. XLS ")
MyFile. Copy (fname)
End the Function

Always does not perform this sentence MyFile. Copy (fname) address format is wrong, it is a great god

CodePudding user response:

You check the fname,/symbol will appear here, in the file is not allowed, so fail,
To try this: DSTR=format $(date, "yyyy - mm - dd)"

CodePudding user response:

reference 1st floor Topc008 response:
you check the fname,/symbol will appear here, in the file name is not allowed, so fail,
To try this: DSTR=format $(date, "yyyy - mm - dd")
or not, said there are invalid characters, should is $

CodePudding user response:

DSTR fname="d: " + + ". XLS "
A debug statements after
The Debug. Print fname
Look at what is inside,

Your post is not the source code? The equals sign before should be automatically add Spaces,

CodePudding user response:

VBS, can play a breakpoint look fname content,

CodePudding user response:

refer to the second floor laoshuzhuomao123 response:
Quote: refer to 1st floor Topc008 response:
you check the fname,/symbol will appear here, in the file name is not allowed, so fail,
To try this: DSTR=format $(date, "yyyy - mm - dd")
or not, said there are invalid characters, should is $

There is no format will not be a VBS function? If you do, don't know the year, month, day use function such as?
A: DSTR=year () & amp; "-" & amp; The month () & amp; "-" & amp; Day ()

Or: DSTR=replace (FormatDateTime (Date), "/", "-") 'this can always

What, still won't do... My God... Check the function of VBS yourself, I'm a little used,

CodePudding user response:

The format is a function of the String class in VBA,

DSTR=FormatDateTime (Date) will make DSTR contains/character, as the file name must not,
Use this one instead:
DSTR=year (Date) & amp; "-" & amp; The month (Date) & amp; "-" & amp; Day (Date)

CodePudding user response:

COPY a parameter?
  • Related