'-------------------------------------------------------------------
'Extrait le PDF Acrobat en passant par un ZIP du Workbook et les BIN
'-------------------------------------------------------------------
Private Sub AcrobatPDFShow(Shape As Shape, pdfFileName As String)
Dim oShell As Object
Dim embbededFilesFolder As Object
Dim binItems As Object
Dim binItem As Object
Dim zipPath As String
Dim binPath As String
Dim pdfPath As String
Dim fileNum As Integer
Dim fileSize As Long
Dim Text As String
Dim startPos As Long
Dim endPos As Long
Application.ScreenUpdating = False
'Ajout d'un nouveau classeur
Application.Workbooks.Add
Shape.Copy
ActiveSheet.Paste
'ZIP file full name en répertoire TEMP
zipPath = Environ("TEMP") & "\" & ActiveWorkbook.Name & ".zip"
If Not Len(Dir(zipPath)) = 0 Then
Kill zipPath
End If
'Save the Workbook as ZIP file
ActiveWorkbook.SaveAs zipPath
ActiveWorkbook.Close savechanges:=False
Set oShell = CreateObject("Shell.Application")
Set embbededFilesFolder = oShell.Namespace(zipPath & "\xl\embeddings")
'Set binItem = embbededFilesFolder.items(1) -> Erreur !
Set binItems = embbededFilesFolder.items
'Il n'y en a qu'un seul mais obligé de faire cette boucle
For Each binItem In binItems
binPath = Environ("TEMP") & "\" & binItem.Name
pdfPath = Environ("TEMP") & "\" & pdfFileName
On Error Resume Next
Kill binPath
Kill pdfPath
On Error GoTo 0
'Copy le .bin du ZIP dans le répertoire TEMP
oShell.Namespace(Environ("TEMP")).CopyHere binItem, 4
'Lecture du fichier .txt du répertoire TEMP
fileNum = FreeFile
Open binPath For Binary Access Read As #fileNum
fileSize = LOF(fileNum)
Text = String(fileSize + 1, Chr(0))
Get #fileNum, , Text
Close #fileNum
'Start of PDF
startPos = InStr(Text, "%PDF")
'End of PDF
endPos = InStrRev(Text, "%%EOF")
endPos = endPos + 4
'Extraction et écriture du fichier PDF
If startPos >= 0 And endPos > startPos Then
Text = Mid(Text, startPos, endPos - startPos + 1)
fileNum = FreeFile
Open pdfPath For Binary Access Write As #fileNum
Put #fileNum, , Text
Close #fileNum
End If
Next binItem
'Suppression du ZIP
Kill zipPath
'Affichage du fichier
oShell.Open (pdfPath)
End Sub