Execution d'une macro sous excel

arch enemy123456 Messages postés 26 Date d'inscription jeudi 9 novembre 2006 Statut Membre Dernière intervention 8 mai 2007 - 26 déc. 2006 à 10:32
ljouvenaux Messages postés 5 Date d'inscription mardi 29 avril 2003 Statut Membre Dernière intervention 29 décembre 2006 - 29 déc. 2006 à 16:32
bonjour,
bah j ai crée une application sous VBA elle marche bien et tout, mais j ai un petite souci
j ai crée une boutton dans une feuille qui ouvre l'application " UserForm1.show " sa marche
mais moi je veux s'avoire si il est possible de crée une Batch ou un truc paraeille qui va lancer
l'application sans passer sur l'ouverture d'excel et merci .
Ps: vraiment j ai bloqué là

4 réponses

fiko81 Messages postés 381 Date d'inscription vendredi 24 septembre 2004 Statut Membre Dernière intervention 5 septembre 2010 3
26 déc. 2006 à 10:45
Salut,
Ton problème ne peut être résolu avec VBA car tu ne pourras pas exécuter ton prog sans excel.
La limite de VBA c'est que tu ne peux pas générer des éxécutables.
--> Donc il faut passer sous VB.

 Fiko ;-)

La reponse vous convient pensez > Accepter < <hr />
0
cavo789 Messages postés 168 Date d'inscription vendredi 9 janvier 2004 Statut Membre Dernière intervention 28 juillet 2009 1
27 déc. 2006 à 09:23
Ce que tu demandes est effectivement impossible : si ta macro se trouve dans Excel, comment veux-tu exécuter la macro si, au préalable, Excel n'est pas ouvert ?

Remarque : il t'est possible de lancer Excel en mode caché (propriété Visible sur False) toutefois je doute que cela réponde à ta question

Christophe
0
ljouvenaux Messages postés 5 Date d'inscription mardi 29 avril 2003 Statut Membre Dernière intervention 29 décembre 2006
29 déc. 2006 à 16:27
Une mini feinte (a developper si tu veux) :
-> je cache la fenetre (probleme  : il n'y a plus de bouton dans la barre de navigation)
> comme cela bloque la visibilite des autres Xcel, il faut une astuce, pour comprendre comment ca marche, j'ai donc utilise un Class Module qui se declenche a chaque ouverture de fichier : si le fichier ouvert est le mien, je le ferme et le rouvre ailleurs / sinon, je ferme l'autre et le rouvre ailleurs)

-> mais ce n'est pas parfait non plus (vous verrez dans les commentaires, il y a encore du travail!)

J'ai donc :

Dans le workbook directement :
Private Sub Workbook_Open()
    Call StartAutomatic
End Sub

Dans un module :
Private p_evtEvents As XlEvents
Public ThisOneIsTheGoodOne As Workbook
Sub StartAutomatic()
    Set ThisOneIsTheGoodOne = ThisWorkbook
    Set p_evtEvents = New XlEvents
    Application.Visible = False
    'The UserForm ShowModal Property Should be set to False
    UserForm1.Show
End Sub
Sub test()
    Application.Visible = True
    Debug.Print Application.Workbooks("PERSONAL.XLS").FullName
End Sub

Dans un class module nomme "XlEvents"
Private WithEvents XlApp As Excel.Application



Private Sub Class_Initialize()
    Set XlApp = Application
End Sub



Private Sub XlApp_WorkbookOpen(ByVal Wb As Workbook)
    'opening a Workbook put the app visible
    Application.Visible = False
   
    For Each mywbk In Application.Workbooks
        If Not Wb Is ThisOneIsTheGoodOne And Not Wb.Name = "PERSONAL.XLS" Then
            wbname = ThisOneIsTheGoodOne.FullName
            aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
                & " " & Chr(34) & wbname & Chr(34) _
                , vbMaximizedFocus _
                )
            ThisOneIsTheGoodOne.Close
            Exit Sub
        End If
    Next

    wbname =Wb.Name
    'This part could be greatly improved : in case we find another window
    'then instead of doing a simple shell (new window each time),
    'we could try to locate the other window and open it there !!!
        aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
                & " " & Chr(34) & wbname & Chr(34) _
                , vbMaximizedFocus _
              )
        Wb.Close savechanges:=False
End Sub
0
ljouvenaux Messages postés 5 Date d'inscription mardi 29 avril 2003 Statut Membre Dernière intervention 29 décembre 2006
29 déc. 2006 à 16:32
Une mini feinte (a developper si tu veux) :
-> je cache la fenetre (probleme  : il n'y a plus de bouton dans la barre de navigation)
> comme cela bloque la visibilite des autres Xcel, il faut une astuce, pour comprendre comment ca marche, j'ai donc utilise un Class Module qui se declenche a chaque ouverture de fichier : si le fichier ouvert est le mien, je le ferme et le rouvre ailleurs / sinon, je ferme l'autre et le rouvre ailleurs)

-> mais ce n'est pas parfait non plus (vous verrez dans les commentaires, il y a encore du travail!)

J'ai donc :

Dans le workbook directement :
Private Sub Workbook_Open()
    Call StartAutomatic
End Sub

Dans un module :
Private p_evtEvents As XlEvents
Public ThisOneIsTheGoodOne As Workbook
Sub StartAutomatic()
    Set ThisOneIsTheGoodOne = ThisWorkbook
    Set p_evtEvents = New XlEvents
    Application.Visible = False
    'The UserForm ShowModal Property Should be set to False
    UserForm1.Show
End Sub
Sub test()
    Application.Visible = True
    Debug.Print Application.Workbooks("PERSONAL.XLS").FullName
End Sub

Dans un class module nomme "XlEvents"
Private WithEvents XlApp As Excel.Application



Private Sub Class_Initialize()
    Set XlApp = Application
End Sub



Private Sub XlApp_WorkbookOpen(ByVal Wb As Workbook)
    'opening a Workbook put the app visible
    
    
    For Each mywbk In Application.Workbooks
        If Not Wb Is ThisOneIsTheGoodOne And Not Wb.Name = "PERSONAL.XLS" Then
            wbname = ThisOneIsTheGoodOne.FullName
            aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
                & " " & Chr(34) & wbname & Chr(34) _
                , vbMaximizedFocus _
                )
            ThisOneIsTheGoodOne.Close
            Exit Sub
        End If
    Next
    Application.Visible = False
    wbname  =Wb.Name
    'This part could be greatly improved : in case we find another window
    'then instead of doing a simple shell (new window each time),
    'we could try to locate the other window and open it there !!!
        aa = Shell(Chr(34) & Application.Path & "\excel.exe" & Chr(34) _
                & " " & Chr(34) & wbname & Chr(34) _
                , vbMaximizedFocus _
              )
        Wb.Close savechanges:=False
End Sub
0
Rejoignez-nous