1
votes

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?

2
Stupid guess but: are macros enabled in that instance of excel?assylias
Yes macros are enabled in all instances. The macro actually runs to that certain point.TheJoeIaut
Have you tried using the full name (something like Application.Run "'" & Makro_Path & Makro_Nam & "'!MakroIni")?assylias
I tried it, but still no difference.TheJoeIaut
I just noticed the instances where this problem occur are 64 bit installations. When running other macros from the old workbook i get an error that i should run them ptr safe.TheJoeIaut

2 Answers

1
votes

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.

0
votes

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.