VBScript编译错误:语句的预期结束

时间:2018-02-23 10:58:21

标签: vbscript

我正在尝试执行一个VB脚本来复制粘贴文件并重命名当前时间系统显示错误。

错误 - Microsoft VBScript编译错误:预期的语句结束

ExecuteInsert
Sub ExecuteInsert()
    Const DestinationFolder = "D:\Temp\Help\"
    Const SourceFolder = "D:\Temp\"
    Const SourceFile = "DataFile.xlsx"
    dim DestinationFile as String
    DestinationFile = "DataFile_" & Format(Now, "dd_mm_yyyy hh_mm") & ".xlsx"
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile SourceFolder & SourceFile, DestinationFolder, True
    Name DestinationFolder & SourceFile As DestinationFolder & DestinationFile
    Set fso = Nothing
End Sub

1 个答案:

答案 0 :(得分:1)

VBScript不支持键入的dim,所有变量都是相等的:Variants。所以:

    dim DestinationFile as String
==>
    dim DestinationFile

该行

Name DestinationFolder & SourceFile As DestinationFolder & DestinationFile

也无效VBScript;我不知道如何纠正它,因为我不知道你想要实现什么。