【问题标题】:Type-Error when trying to saving with VB script尝试使用 VB 脚本保存时出现类型错误
【发布时间】:2012-12-14 18:18:46
【问题描述】:

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

 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

我觉得我需要将文件名定义为一个字符串,但我不确定如何在不出错的情况下做到这一点

【问题讨论】:

    标签: string vbscript save filenames typeerror


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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-30
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 2019-05-12
      • 2019-10-18
      相关资源
      最近更新 更多