在excel 2010中执行宏的运行时错误

时间:2012-05-08 10:05:32

标签: excel vba excel-vba excel-2010

我收到了:

  

运行时错误'1004':无法运行宏Makros.xlm!MakroIni。该   宏可能在此工作簿中不可用或所有宏都可用   禁用。

...在Excel 2010的某些实例中运行宏时。在某些Excel 2010安装和Excel 2003中,它可以正常工作。

涉及2个工作簿:Macro.xlm和Username.xls。这两个文件都存储在远程服务器上。

宏执行时崩溃:

Workbooks.Open Makro_Path & Makro_Nam, ReadOnly:=True
Application.Run Makro_Nam & "!MakroIni", WbTyp

第一行正确执行,所有宏都可见。 Makro_Nam定义为:

Public Const Makro_Nam As String = "Makros.xlm"

我该怎么办?

2 个答案:

答案 0 :(得分:1)

实际上原因是Excel 64位。

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

我把它们改成了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

现在似乎有效。

答案 1 :(得分:0)

根据你的宏所做的,显而易见的答案似乎是你需要设置

ReadOnly:=True

ReadOnly:=False

这样您的宏就可以对数据进行更改。