vba 在 excel 2010 中执行宏的运行时错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10496520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
runtime error executing macro in excel 2010
提问by TheJoeIaut
I am receiving:
我收到:
Run-time error '1004': Cannot run macro Makros.xlm!MakroIni. The macro may not be available in this workbook or all macros may be disabled.
运行时错误“1004”:无法运行宏 Makros.xlm!MakroIni。宏在此工作簿中可能不可用,或者可能禁用了所有宏。
...when running a Macro in certain instances of Excel 2010. In some Excel 2010 installations and Excel 2003 it works fine.
...在 Excel 2010 的某些实例中运行宏时。在某些 Excel 2010 安装和 Excel 2003 中,它工作正常。
There are 2 Workbooks involved: Macro.xlm and Username.xls. Both files are stored on a remote server.
涉及 2 个工作簿:Macro.xlm 和 Username.xls。这两个文件都存储在远程服务器上。
The Macro crashes when executing:
执行时宏崩溃:
Workbooks.Open Makro_Path & Makro_Nam, ReadOnly:=True
Application.Run Makro_Nam & "!MakroIni", WbTyp
The first line is proper executed and all macros are visible. Makro_Nam is defined as:
第一行正确执行,所有宏都可见。Makro_Nam 定义为:
Public Const Makro_Nam As String = "Makros.xlm"
What can i do?
我能做什么?
采纳答案by TheJoeIaut
Actually the cause was Excel 64 bit.
实际上原因是Excel 64位。
The Makro.xlm worksheet contained this function definitions:
Makro.xlm 工作表包含以下函数定义:
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" ( _
ByVal lpFileName As String, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" ( _
ByVal hFindFile As Long, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32.dll" ( _
ByVal hFindFile As Long) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" ( _
ByRef lpFileTime As FILETIME, _
ByRef lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" ( _
ByRef lpFileTime As FILETIME, _
ByRef lpSystemTime As SYSTEMTIME) As Long
I changed them to ptrsafe:
我将它们更改为 ptrsafe:
Private Declare PtrSafe Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" ( _
ByVal lpFileName As String, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare PtrSafe Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" ( _
ByVal hFindFile As Long, _
ByRef lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare PtrSafe Function FindClose Lib "kernel32.dll" ( _
ByVal hFindFile As Long) As Long
Private Declare PtrSafe Function FileTimeToLocalFileTime Lib "kernel32.dll" ( _
ByRef lpFileTime As FILETIME, _
ByRef lpLocalFileTime As FILETIME) As Long
Private Declare PtrSafe Function FileTimeToSystemTime Lib "kernel32.dll" ( _
ByRef lpFileTime As FILETIME, _
ByRef lpSystemTime As SYSTEMTIME) As Long
Now it seems to work.
现在它似乎起作用了。
回答by hireSwish
Depending on what your macro does, the obvious answer seems to be that you need to set
根据您的宏的作用,显而易见的答案似乎是您需要设置
ReadOnly:=True
to be
成为
ReadOnly:=False
So that your macro can make changes to the data.
这样您的宏就可以对数据进行更改。