Page 1 sur 1

[..] Impossible de lancer une macro Excel

Posté : mer. 27 mai 2009 10:45
par senpaijp
Bonjour à tous,

J'utilise AutoIt3 depuis peu.
J'aimerais lancer une macro VBA qui est dans un fichier Excel.

Code : Tout sélectionner

#include <ExcelCOM_UDF.au3>
        $oExcel = _ExcelBookOpen ("<chemin>\titi.xls", 1)

        If @error = 1 Then
            MsgBox (0, "Error!", "Unable to start Excel object")
            Exit
        ElseIf @error = 2 Then
            MsgBox(0, "Error!", "File does not exist")
            Exit
        EndIf
        
        _ExcelWriteCell ($oExcel, "coucou", 1, 1) ; ça marche nikel :))))


        $oExcel.Application.Run ("ma_macro")   ; cette ligne ne fonctionne pas :(((
        
        _ExcelBookClose ($oExcel)
 
L'erreur est:
$oExcel.Application.Run ("ma_macro")
$oExcel.Application.Run ("ma_macro")^ERROR

Error: The requested action with this object has failed


La macro Excel est très simple:

Code : Tout sélectionner

Sub toto()
    range("H6").Select
    ActiveCell.Text = "TOTO"
End Sub
 
Est-ce que l'appel à la macro est correct ?
Ne faut-il pas nommer la feuille qui contient la fonction Excel ?