Annuler ouverture pdf

Bonjour a tous

un dernier petit soucis . dans le usf j'ai une listbox "accès au pdf" si je sélectionne le nom du fichier dans cette listbox et que je fait cliquer j'ai un message qui me demande si ok ou annuler . si je met ok tout va bien mais si je met annuler j'ai le message de microsoft vba "deboger"

peut on régler cela

4excel-ssi.xlsm (129.88 Ko)

Bonjour Chtimili

Voici ton fichier modifié, mieux vaut utiliser ShellExecute plutôt que FollowHyperlink

Il faut juste déclarer l'API Windows

' Constante Win64 qui vaut True uniquement si Office est installé en 64 bits.
#If Win64 Then
  Private Declare PtrSafe 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
#Else
  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
#End If

Ensuite dans le code de ton bouton, tu mets

Private Sub CommandButton4_Click()
  Dim sNomFic As String, sDos As String
  sDos = "U:\Desktop\DOSSIER SSI 2\LOCALISATION SSI-PLANS PDF\"
  sNomFic = Me.ListBox1.List(Me.ListBox1.ListIndex) & ".pdf"
  ' Vérifier l'existence du fichier
  If Not (Dir(sDos & sNomFic) = sNomFic) Then
    MsgBox ("la procedure ne parvient pas a trouver un fichier portant ce nom")
    Exit Sub
  Else
  ' Si existe
  'ThisWorkbook.FollowHyperlink "U:\Desktop\DOSSIER SSI 2\LOCALISATION SSI-PLANS PDF\" & ListBox1.List(ListBox1.ListIndex) & ".pdf"
  ShellExecute 0, vbNullString, sDos & sNomFic, vbNullString, vbNullString, 0
  End If
End Sub

A+

Un Grand Merci

cdt

chtimili

Rechercher des sujets similaires à "annuler ouverture pdf"