La Web del Programador: Comunidad de Programadores
 
    Pregunta:  51656 - EJECUTAR MACRO DESDE VISUAL BASIC
Autor:  Arlet Padilla
Necesito desde Visual Basic ejecutar una macro, el codigo que estoy utilizando es este:

Set loexcel = CreateObject("Excel.Application")
Set libro = loexcel.Workbooks.Open("C:\automa\datos\CIFRAS.XLS"
loexcel.Visible = True
loexcel.Application.Run "c:\automa\macro\MACRO.XLA"

pero me marca el error 1004 y dice que la macro no existe (estoy segura de que existe)

Agradezco de antemano la ayuda que puedan brindarme.

  Respuesta:  eider mauricio aristizabal erazo
te falta colocar el nombre de la macro y luego sus argumentos por ejemplo para ejecutar la macro obetner nombreedad que que requier un argumento cadena y uno numerico, seria asi:
Application.Run "c:\automa\macro\MACRO.XLA!obtener_nombreEdad", "Minombre", 10

espero te sirva de algo:
Remarks
You cannot use named arguments with this method. Arguments must be passed by position.

The Run method returns whatever the called macro returns. Objects passed as arguments to the macro are converted to values (by applying the Value property to the object). This means that you cannot pass objects to macros by using the Run method.

Example
This example shows how to call the function macro My_Func_Sum, which is defined on the macro sheet Mycustom.xlm (the macro sheet must be open). The function takes two numeric arguments (1 and 5, in this example).

mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
MsgBox "Macro result: " & mySum

The information above was taken from microsoft excel help

Bye