Shellexecute aidez moi!

Résolu
ticrain Messages postés 178 Date d'inscription jeudi 15 mars 2007 Statut Membre Dernière intervention 2 janvier 2015 - 26 avril 2007 à 14:23
 mortalino - 28 avril 2007 à 01:03
Je dois ouvrir des fichier excel et word que joré selectionner dans une listobox en appuyant sur un bouton:
est ce que qqun peut m'aider je c que shellexecute est efficace pour cela, g commencé un bout de code mais je c pas le finir ce que je peut vous dire c'est que les fichier .DOC et .XLS se trouve sur C:.
J'ai commencé se bout de code mais je c meme pas si je pars dans le bon sens? et surtout il est pas fini si qqun peut m'aider se serai sympa.

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


Private Sub CommandButton2_Click()
Dim nomdoc As String
nomdoc = ListBox1.List(ListBox1.ListIndex)
...........
..........je sais plus après

Merci

101 réponses

jrivet Messages postés 7393 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
27 avril 2007 à 09:28
Salut,
Bah minute papillon, j'ai un travail aussi
tiens teste ceci

Option Explicit
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
Private Const SW_MAXIMIZE = 3
Private Sub commandbutton2_Click()
Dim nomdoc As String
Dim i As Integer
'Pour faire référence a ton classeur
'de départ (pas sur que ce soit utile mais bon)
'teste sans si tu veux
Dim WbDepart As Workbook
   Set WbDepart = ActiveWorkbook
   For i = 0 To ListBox1.ListCount - 1
       If ListBox1.Selected(i) Then
           nomdoc = ListBox1.List(i)
           'on regarde si l'extension du fichier est un classeur
           If UCase(Mid(nomdoc, InStrRev(nomdoc, ".") + 1)) = "XLS" Then
               'on fait alors appel a Excel pour ouvrir le doc
               Call Application.Workbooks.Open("C:\" & nomdoc)
               Call WbDepart.Activate
           Else
               'Sinon ShellExecute
               Call ShellExecute(0, "open", "C:\" & nomdoc, vbNullString, vbNullString, SW_MAXIMIZE)
           End If
       End If
   Next
   Set WbDepart = Nothing
End Sub , ----
[code.aspx?ID=41455 By Renfield]

@+: Ju£i?n
Pensez: Réponse acceptée
3
Rejoignez-nous