尝试使用VB脚本保存时出现类型错误

时间:2012-12-14 18:18:46

标签: string vbscript save filenames typeerror

我正在尝试使用以下脚本,它在以下粗体代码行中给出了类型错误。

 Option Explicit

 Dim xlApp
 Dim xlBook
 Dim Filename
 Dim Format

 Set xlApp = CreateObject("Excel.Application")
 Set xlBook = xlApp.Workbooks.Open("\\denfs1\home\davidvan\desktop\shane spread sheet 2.xlsm", 0, True)

 xlApp.Run "Mail_Body"
 **xlBook.SaveAS Filename=("H:Contrabutions spread sheet" & Format(Date,"MM/DD/YYYY")& ".xlsm")**
 xlBook.close
 xlApp.Quit


 Set xlBook = Nothing
 Set xlApp = nothing

我觉得我需要将文件名定义为字符串,但我不确定如何在发出错误时这样做

1 个答案:

答案 0 :(得分:1)

  1. VBScript中没有Format()函数(而不是VBA),查找FormatDateTime()而不是
  2. VBScript中没有命名参数(VBA中的语法涉及“:=”),使用普通字符串作为.SaveAs方法的第一个参数
  3. VBScript解析器在字符串连接运算符
  4. 周围不需要空格