Lancer une macro via un userform

Bonjour,

J'aimerai à partir de mon userform pouvoir lancer directement ma macro qui est déja programmée via laquelle j'imprime des documents.

Mon userform est deja crée seulement quand je clique sur le bouton "imprimer" de mon userform rien ne se passe. Quelqu'un aurait-il une formule à me proposer??

Bonjour,

Pouvez vous partager les macros utilisées, voire un fichier type ?

Bonjour,

Voici un extrait de la macro :

[size=85][i][b]Sub Macro1()

   UserForm11.Show
  Sheets("autorisation").Cells(1, 2) = ""
   Sheets("autorisation").Select
    Sheets("Feuil3").Cells(1, 2) = ""

   For Lig = 8 To 110

        If Sheets("autorisation").Cells(1, 2) = "" Or Sheets("formations").Cells(Lig, 1) = Sheets("autorisation").Cells(1, 2) Then
         If Sheets("formations").Cells(Lig, 50) <> "X" Then

            Range("E4:G24").Select
            Selection.ClearContents

            Range("E27:G47").Select
            Selection.ClearContents

            Sheets("autorisation").Cells(19, 2) = Sheets("formations").Cells(Lig, 1)
            Sheets("autorisation").Cells(19, 3) = Sheets("formations").Cells(Lig, 2)
            Sheets("autorisation").Cells(21, 3) = Sheets("formations").Cells(Lig, 3)
            Sheets("autorisation").Cells(23, 3) = Sheets("formations").Cells(Lig, 4)

            Sheets("autorisation").Cells(42, 2) = Sheets("formations").Cells(Lig, 1)
            Sheets("autorisation").Cells(42, 3) = Sheets("formations").Cells(Lig, 2)
            Sheets("autorisation").Cells(44, 3) = Sheets("formations").Cells(Lig, 3)
            Sheets("autorisation").Cells(46, 3) = Sheets("formations").Cells(Lig, 4)
        lig1 = 3
        lig24 = 27
        If Sheets("formations").Cells(Lig, 11) > " " Then
            lig1 = lig1 + 1
            Sheets("autorisation").Cells(lig1, 5) = "CACES R389 CAT 3"
            Sheets("autorisation").Cells(lig1, 6) = Sheets("formations").Cells(Lig, 11)
            Sheets("autorisation").Cells(lig1, 7) = Sheets("formations").Cells(Lig, 12)
         End If

          If Sheets("formations").Cells(Lig, 11) > " " Then
            lig24 = lig24 + 1
            Sheets("autorisation").Cells(lig24, 5) = "CACES R389 CAT 3"
            Sheets("autorisation").Cells(lig24, 6) = Sheets("formations").Cells(Lig, 11)
            Sheets("autorisation").Cells(lig24, 7) = Sheets("formations").Cells(Lig, 12)
         End If  
        End If
        Application.Wait (Now + TimeValue("0:00:04"))   
     End If
     End If

       Next Lig
   Sheets("autorisation").Select               
    Range("A3").Select
End Sub
[/b][/i][/size]
Et voici mon UserForm 11 : 
[size=85][b][i]Private Sub btimp_Click()
    'Sheets("autorisation").Select
    'ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
    'IgnorePrintAreas:=False        
End Sub
Private Sub CommandButton1_Click()
    End
End Sub[/i][/b][/size]

C'est un peu imbuvable ! Merci de modifier votre post pour :

  • Supprimer les surplus de saut de ligne (et éviter d'avoir 3 km de code !)
  • Utiliser la mise en forme proposée par le forum (balises
    pre___XLPSPXLP___000001
    , voir bouton </>)

PS : merci de le faire avec le code d'origine, puisque l'indentation à disparue avec votre première copie.

J'espère que c'est mieux comme ceci

J'espère que c'est mieux comme ceci

Oui c'est plus lisible, merci.

Désolé je ne vais pas aborder le cœur de votre demande faute de compétences.

En revanche, quelques suggestions sur le code :

- Select et Activate son inutiles, exemple :

Range("E4:G24").Select
Selection.ClearContents
'Devient :
Range("E4:G24").ClearContents

- Pour alléger le code, utiliser des variables plutôt que le nom complet des feuilles, et/ou une structure With (voir exemples ci-dessous) :

Dim FForm As Worsheet
'...
Set FForm = Worksheets("formations")
With Sheets("autorisation")
        .Cells(lig24, 5) = "CACES R389 CAT 3"
        .Cells(lig24, 6) = FForm.Cells(Lig, 11)
        .Cells(lig24, 7) = FForm.Cells(Lig, 12)
End With
'...
  • Syntaxe incohérente : If Sheets("formations").Cells(Lig, 11) > " " Then. Il ne peut y avoir de comparaison mathématique avec une chaine de caractères
  • Doublon dans le code :
 If Sheets("formations").Cells(Lig, 11) > " " Then
        lig24 = lig24 + 1
        Sheets("autorisation").Cells(lig24, 5) = "CACES R389 CAT 3"
        Sheets("autorisation").Cells(lig24, 6) = Sheets("formations").Cells(Lig, 11)
        Sheets("autorisation").Cells(lig24, 7) = Sheets("formations").Cells(Lig, 12)
 End If

Concernant la demande initiale, il faudrait à mon avis joindre un fichier...

Merci pour votre réponse!

Je n’arrive pas à joindre le fichier il est trop lourd

Rechercher des sujets similaires à "lancer macro via userform"