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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| Sub LirePDF()
Dim s() As String
Dim NumFacture, NomConsultant, NomSociete, MoisConcerne, Reponse As String
Dim Chemin, NewChemin As String
Dim Renom As String
'http://www.eileenslounge.com/viewtopic.php?f=30&t=5907
Dim strPDF As String, strTmp As String, i As Integer
' The next ten lines and the last line in this sub can help if
' you get "ActiveX component can't create object" errors even
' though a Reference to Acrobat is set in Tools|References.
Dim bTask As Boolean
bTask = True
'If Tasks.Exists(Name:="Adobe Acrobat Professional") = False Then
bTask = False
Dim AdobePath As String, WshShell As Object
Set WshShell = CreateObject("Wscript.shell")
AdobePath = WshShell.RegRead("HKEY_CLASSES_ROOT\acrobat\shell\open\command\")
AdobePath = Trim(Left(AdobePath, InStr(AdobePath, "/") - 1))
Shell AdobePath, vbHide
'End If
'Replace FilePath & Filename with the correct FilePath & Filename for the pdf file to be read.
NumFacture = ActiveCell.Value
NomConsultant = ActiveCell.Offset(0, 1).Value
Chemin = "C:\Users\xxx\Downloads\" 'path ou le fichier est sauvegardé par défaut
strPDF = ReadAcrobatDocument(Chemin & NumFacture & ".pdf") '***Use your path.
Debug.Print strPDF
s() = Split(strPDF, vbLf)
NomSociete = Split(LTrim(s(7)) & Space(1))(0)
'recherche de données pour les variables
For i = 1 To 40
On Error Resume Next
If s(i) Like "*COMMENTAIRE*" Then
MoisConcerne = s(i + 2) 'le mois est en général sur la deuxième ligne
If NomConsultant = Trim(Mid(s(i + 1), InStrRev(s(i + 1), " ") + 1)) Then 'si différence entre nom rentré et facture alors
Else
Reponse = MsgBox("Problème nom consultant cliquez " & vbLf & "OUI pour " & NomConsultant & vbLf & "NON pour " & _
Mid(s(i + 1), InStrRev(s(i + 1), " ") + 1), vbYesNo)
If Reponse = vbYes Then
NomConsultant = NomConsultant
Else
NomConsultant = Trim(Mid(s(i + 1), InStrRev(s(i + 1), " ") + 1))
End If
End If
End If
Next
'If bTask = False Then Tasks.Item("Adobe Acrobat Professional").Close
' changement de nom et répertoire
NewChemin = "C:\_data travailxxx\" 'path ou on sauvegardera la facture modifiée et finalisée
Renom = NomConsultant & " FACTURE " & NumFacture & " - " & MoisConcerne & " " & NomSociete 'changement du nom de la facture
Name Chemin & NumFacture & ".pdf" As NewChemin & Renom & ".pdf" 'déplacement du fichier de téléchargement à travail_xxx
ActiveCell.Offset(1, 0).Select
End Sub |
Partager