从.vbs文件调用VBA宏会引发800A03EC错误 [英] Calling VBA macro from .vbs file throws 800A03EC error

查看:91
本文介绍了从.vbs文件调用VBA宏会引发800A03EC错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过.VBS文件(文件名:Check_final.vbs)运行VBA宏.这是代码

I'm trying to run a VBA macro through .VBS file(File name: Check_final.vbs). Here is the code

Option Explicit

run_macro

Sub run_macro()
    Dim xl1
    Dim sCurPath
    Dim xlBook
    Dim FolderFromPath
    Set xl1 = CreateObject("Excel.application")

    sCurPath =Wscript.ScriptFullName                                                                            
    Set xlBook = xl1.Workbooks.Open(sCurPath, 0, True)
    xl1.DisplayAlerts = False
    FolderFromPath = Left(sCurPath, InStrRev(sCurPath, "\"))
    xl1.Application.run FolderFromPath & "Changed_chk.xlsm!Check"

    Set xlBook = Nothing
End Sub

运行此.vbs文件时,出现带有只读和通知选项的弹出窗口'Changed_chk.xlsm已被锁定以进行编辑'.如果我通过只读"或通知"选项确认它,则以Check_final(即该.vbs文件的文件名)的名称打开一个excel工作表,并且上述代码显示为写在该excel文件中.然后我收到一个Windows脚本宿主错误(代码:800A03AC),说该宏可能不可用或所有宏都被禁用.(尽管我已按此处所述启用了该宏.[

When I run this .vbs file I get this popup 'Changed_chk.xlsm is locked for editing' with Read only and notify options. If I acknowledge it with either Read only or notify option a excel sheet is opened in the name of Check_final (which is the file name of that .vbs file) and the above mentioned code is shown written in that excel file. Then I get a Windows script host error(code: 800A03AC) saying macro may not be available or all macro's are disabled.(Though I have enabled the macro as mentioned here.[http://www.addictivetips.com/windows-tips/enable-all-macros-in-excel-2010/)]. Any help on this is much appreciated. Thanks in advance.

推荐答案

您打开的vbs文件而不是excel文件...此外,请确保您的函数/子文件是公共的.在下面的示例中,我在模块"YourModuleName"中创建了一个Public Sub Check,从vbs文件中调用该文件.

You open your vbs-file instead of your excel-file... Also make sure that your function/sub is public. In the example below, I created a Public Sub Check in the module "YourModuleName", which I call from the vbs-file.

Option Explicit

run_macro

Sub run_macro()
    Dim xl1
    Dim xlBook
    Dim FolderFromPath
    Set xl1 = CreateObject("Excel.application")

    FolderFromPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 
    set xlBook = xl1.Workbooks.Open(FolderFromPath & "Changed_chk.xlsm")
    xl1.Application.run "'" & xlBook.Name & "'!YourModuleName.Check"
    xl1.Application.Quit
End Sub

这篇关于从.vbs文件调用VBA宏会引发800A03EC错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆