Reputation: 1532
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.
...when running a Macro in certain instances of Excel 2010. In some Excel 2010 installations and Excel 2003 it works fine.
There are 2 Workbooks involved: Macro.xlm and Username.xls. Both files are stored on a remote server.
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:
Public Const Makro_Nam As String = "Makros.xlm"
What can i do?
Upvotes: 1
Views: 6546
Reputation: 1532
Actually the cause was Excel 64 bit.
The Makro.xlm worksheet contained this function definitions:
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:
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.
Upvotes: 1
Reputation: 650
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.
Upvotes: 0