Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    Option Compare Text 'permet de ne pas faire de distinction entre minuscule et majuscule
       Option Explicit
 
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
            (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
        Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
            (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String _
            , ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Sub ImprimerFichier()
    Dim chemin As String
    Dim x As Long
    Dim nom As String
    Dim Cellule As Range
    Dim firstAddress As String
    Dim format As String
 
 
    nom = InputBox(" Quel est le nom du fichier que vous voulez imprimer?")
               Application.ScreenUpdating = False
 
 
    With ActiveSheet.Range("A7:A45")
        Set Cellule = .Find(nom, Lookat:=xlWhole)
        If Not Cellule Is Nothing Then
            firstAddress = Cellule.Address
            Do
                Exit Sub
                Set Cellule = .FindNext(Cellule)
            Loop While Not Cellule Is Nothing And Cellule.Address <> firstAddress
        End If
    End With
        MsgBox "Le fichier n'existe pas"
            x = FindWindow("XLMAIN", Application.Caption)
            chemin = "E:\vba\base VBA\"
            format = ".pdf"
 
            ShellExecute x, "print", chemin & "nom" & format, "", "", 1
        End Sub