Problème ouverture doc. PDF à partir d'un bouton d'un userform

anakin_74 -  
f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

voici mon problème:

Sur un dossier Excel 2010, dans un userform j'ai un bouton qui va ouvrir un dossier dans l'explorer suivant un chemin défini.
Il s'ouvre bien au bon endroit.
J'arrive à ouvrir les documents du pack office (word, Excel,...), mais concernant les PDF ça déconne! J'ai la fenêtre "Text Import Wizard" qui s'ouvre. Donc si je valide les différentes opérations j'aboutis à document excel avec des caractères bizards. C'est pas ce que je veux !

voici ma macro en VBA:

Ou est l'erreur ?

Private Sub rapport_etalonnage_Click()

Application.ScreenUpdating = False

Dim chemin2 As String

'nom du chemin
chemin2 = Range("Z1").Value & Range("AA2").Value & Range("V6").Value
   
ChDrive chemin2
ChDir chemin2
Application.Dialogs(xlDialogOpen).Show

Unload Me

End Sub


Merci de votre aide

EDIT: Ajout de la coloration syntaxique.

1 réponse

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    mais concernant les PDF ça déconne! Oui, mais c'est pas excel. Excel n'a jamais ete prevu pour ouvrir des fichiers PDF

    Choix et ouverture fichier(s) PDF sans donner le chemin du .exe du logiciel qui ouvre les fichiers PDF

    code a mettre dans un module:
    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
    Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
    

    'code du bouton
    Private Sub rapport_etalonnage_Click()
        Dim chemin2 As String
        Dim swbName As Variant
    
        'nom du chemin
        chemin2 = Range("Z1").Value & Range("AA2").Value & Range("V6").Value
       
        ChDrive chemin2
        ChDir chemin2
        swbName = Application.GetOpenFilename(" Fichier(s) PDF (*.PDF), *.PDF", 2, "RAPPORT ETALONNAGE", True)
        'pas de fichier
        If swbName = False Then Exit Sub
        
        'Ligne de Code ci-dessous recuperee sur le site Code-source ou developpez.com !!!
        'Permet de lancer un fichier sans donner le chemin du .EXE
        hwndSim = ShellExecuteForExplore(0&, vbNullString, Chemin_Fichier & Nom_Fichier, 0, 0, 1)
    
        Unload Me
    
    End Sub
    0