【问题标题】:Calling a Vba script in a HTML5 page在 HTML5 页面中调用 Vba 脚本
【发布时间】:2017-12-07 00:39:57
【问题描述】:

我在 Vba 中创建了一个脚本,允许在 Word 中比较报告,我想在 HTML 中创建一个页面,允许在单击按钮后启动 Vba 脚本。

当我尝试这样做时,我在 Firefox 和 Chrome 中收到消息“ReferenceError: myFunction is not defined”。如果我在 IE 上尝试相同的操作,我会收到错误“'myFunction' is undefined”。

<!DOCTYPE html>
<html>
  <head>
    <title>Reports Comparison</title>
    <script type="text/vbscript" src="myScript.vbs"></script>
  </head>
  <body>
    <input type="button" value="Test" onClick="myFunction()">
  </body>
</html>

myFunction 在文件 myScript.vbs 中正确定义:

Sub myFunction ()
    Dim strFolderA As String
    Dim strFolderB As String
    Dim strFolderC As String
    Dim strFileSpec As String
    Dim strFileName As String
    Dim objDocA As Word.Document
    Dim objDocB As Word.Document
    Dim objDocC As Word.Document
    strFolderA = InputBox("Enter path to base documents:")
    strFolderB = InputBox("Enter path to new documents:")
    strFolderC = InputBox("Enter path for document comparisons to be saved:")
    strFileSpec = "*.docx"
    strFileName = Dir(strFolderA & strFileSpec)
    Do While strFileName <> vbNullString
        Set objDocA = Documents.Open(strFolderA & strFileName)
        Set objDocB = Documents.Open(strFolderB & strFileName)
        Application.CompareDocuments _
            OriginalDocument:=objDocA, _
            RevisedDocument:=objDocB, _
            Destination:=wdCompareDestinationNew
        objDocA.Close
        objDocB.Close
        Set objDocC = ActiveDocument
        objDocC.SaveAs FileName:=strFolderC & strFileName
        objDocC.Close SaveChanges:=False
        strFileName = Dir
    Loop
    Set objDocA = Nothing
    Set objDocB = Nothing
End Sub

你能帮我做吗?

问候

【问题讨论】:

    标签: html vba internet-explorer


    【解决方案1】:

    VBScript 只能在 Internet Explorer 中使用。即使这样,默认情况下它也不起作用,您必须启用“企业模式”以启用向后兼容性和各种其他标志以允许浏览器访问文件系统。如果没有一些额外的工作,您也无法使用这样的 Word 文档,因为这里不会定义 Word

    有一个新的 Javascript API,您可以利用它来代替,但同样不能在浏览器的上下文中使用。但它可以让你为 word 本身添加一些功能。

    https://dev.office.com/reference/add-ins/javascript-api-for-office

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 1970-01-01
      • 2016-02-01
      • 2012-08-16
      • 2011-10-12
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多