运行时错误1004宏可能在工作簿中不可用,或者可能禁用所有宏。 [英] run time error 1004 the macro may not be available in the workbook or all macros may be disabled.

查看:471
本文介绍了运行时错误1004宏可能在工作簿中不可用,或者可能禁用所有宏。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

我正在尝试从Windows 7上的Access 2016运行此代码。 我收到此错误代码,无法弄清楚原因。   我有两个可以运行代码的同事和一个同事错误的同事。   我已将我的信任中心
设置镜像给可以运行代码但仍然无法运行代码的同事。 

I am trying to run this code from Access 2016 on Windows 7.  I get this error code and can't figure out why.   I have 2 coworkers that can run the code fine and 1 coworker that gets the same error.   I have mirrored my Trust Center Settings to the coworkers that can run the code and still can't run the code. 

错误:  运行时间错误1004宏可能在工作簿中不可用,或者所有宏都可能被禁用。

Error:  run time error 1004 the macro may not be available in the workbook or all macros may be disabled.

代码:




公共函数RunExternalMacro(targetWorkbookPath As String,macroWorkbookPath As String,macroName As String)

  Dim excl As Excel.Application

 设置excl = CreateObject(" Excel.Application"))
  excl.Visible = True

  excl.Workbooks.Open macroWorkbookPath



  excl.Workbooks.Open targetWorkbookPath

  'excl.Run FileName!MacroName

  excl.Run Mid(macroWorkbookPath,InStrRev(macroWorkbookPath," \")+ 1)& "!" &安培;宏名  '这是给我错误的一行。

  excl.Workbooks(2)。保存
  excl.Quit

结束功能

Public Function RunExternalMacro(targetWorkbookPath As String, macroWorkbookPath As String, macroName As String)
  Dim excl As Excel.Application
  Set excl = CreateObject("Excel.Application")
  excl.Visible = True
  excl.Workbooks.Open macroWorkbookPath

  excl.Workbooks.Open targetWorkbookPath
  'excl.Run FileName!MacroName
  excl.Run Mid(macroWorkbookPath, InStrRev(macroWorkbookPath, "\") + 1) & "!" & macroName  ' this is the line that gives me the error.
  excl.Workbooks(2).Save
  excl.Quit
End Function

Excel信任中心宏设置设置为启用所有宏。

Excel Trust Center Macro Settings are set to enable all macros.

推荐答案

听起来更像是一个Excel问题。您的路径和宏名称引用中可能存在语法问题。顺便说一句,宏应该在一个模块中。看下面的页面是否有帮助:

Sounds more like an Excel issue. You probably have a syntax issue in your path and macro name reference. BTW, the macro should be in a Module. See if the below page helps:

https://www.mrexcel.com/forum/excel-questions/606757-run-time-1004-error-when-calling-sub-another-macro- 3.html


这篇关于运行时错误1004宏可能在工作簿中不可用,或者可能禁用所有宏。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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