Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
  2. Dim testo As String
  3. Dim nomefile As String
  4. Dim path As String
  5.  
  6. On Error Resume Next
  7.  
  8. If Target.Column = 5 Then
  9.  
  10. path = "C:UsersAlex"
  11. testo = path & Cells(Target.Row, 5)
  12. nomefile = Dir(Left(testo, Len(testo)) & "*.pdf")
  13.  
  14. If nomefile = "" Then
  15. MsgBox "File non trovato", vbCritical, "ATTENZIONE"
  16. Exit Sub
  17. End If
  18.  
  19. Do
  20. Shell "C:Program Files (x86)AdobeReader 11.0ReaderAcroRd32.exe " & path & nomefile, vbMaximizedFocus
  21. nomefile = Dir
  22. Loop While nomefile <> ""
  23. End If
  24. End Sub
  25.  
  26. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
  27. Dim testo As String
  28. Dim FSO As Object
  29. Dim Folder As Object
  30. Set FSO = CreateObject("Scripting.FileSystemObject")
  31.  
  32. Set Folder = FSO.GetFolder("C:UsersAlex")
  33. ...
  34. ...
  35. testo = path & Cells(Target.Row, 5)
  36. nomefile = FindFile(testo, Folder, FSO)
  37. End Sub
  38.  
  39. Function FindFile(FileName As String, Folder As Object, ByRef FSO As Object) As String
  40. DoEvents
  41.  
  42. If FSO.FileExists(Folder & "" & FileName & ".pdf") Then
  43. FindFile = Folder & "" & FileName & ".pdf"
  44. Exit Function
  45. End If
  46.  
  47. Dim SubFolder As Object
  48. For Each SubFolder In Folder.SubFolders
  49. FindFile = FindFile(FileName, SubFolder, FSO)
  50. Next
  51. End Function
  52.  
  53. Function FindFile(FileName As String, Folder As Object, ByRef FSO As Object) As String
  54. DoEvents
  55.  
  56. If FSO.FileExists(Folder & "" & FileName & "*.pdf*") Then
  57. FindFile = Folder & "" & FileName & "*.pdf*"
  58. Exit Function
  59. End If
  60.  
  61. Dim SubFolder As Object
  62. For Each SubFolder In Folder.SubFolders
  63. FindFile = FindFile(FileName, SubFolder, FSO)
  64. Next
  65.  
  66. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
  67. Dim testo As String
  68. Dim nomefile As String
  69. Dim FSO As Object
  70. Dim Folder As Object
  71.  
  72. Set FSO = CreateObject("Scripting.FileSystemObject")
  73. Set Folder = FSO.GetFolder("C:UsersAlex")
  74. If Target.Column = 5 Then
  75. testo = Cells(Target.Row, 5)
  76. nomefile = FindFile(testo, Folder, FSO)
  77.  
  78. If nomefile = "" Then
  79. MsgBox "File not found!", vbCritical, "WARNING"
  80. Exit Sub
  81. End If
  82.  
  83. CreateObject("WScript.Shell").Run nomefile
  84. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement