[VBA-E] Pb dezipper un fichier
Bonjour,
j'ai un petit pour dezipper un fichier sous vba avec winzip
en mode debug pas a pas ok pas de pb mais en mode automatique
j'ai un message d'erreur
http://megapacman.ifrance.com\Images\pb zip.JPG
voici mon code:
Code:
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
Private Sub UserForm_Initialize()
'Declaration
Dim myItems, myItem, myAttachments, myAttachment As Object
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim extension As String
Dim nameattach As String
Dim zipname As String
Dim nbzip As Integer
Dim myzip As String
Dim myindex As Integer
Dim tabzipfile(30) As String
Dim shellunzip As String
Dim nbattach As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim fso As FileSystemObject
Set fso = New FileSystemObject
'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
'for all items do...
For Each myItem In myOlSel
Debug.Print myItem
zipname = Left(myItem, 14)
Debug.Print zipname
nbzip = 0
k = 0
zipname = Replace(zipname, " ", "")
zipname = Replace(zipname, ":", "")
txtzipname.Value = zipname
'point on attachments
Set myAttachments = myItem.Attachments
'if there are some...
If myAttachments.Count > 0 Then
Debug.Print myAttachments.Count
'for all attachments do...
For i = 1 To myAttachments.Count
Debug.Print i
'save them to destination
Debug.Print myAttachments(i)
extension = Right(myAttachments(i), 3)
Debug.Print extension
If ((extension = "doc") Or (extension = "DOC")) Then
Listfile.AddItem myAttachments(i)
Debug.Print myAttachments(i)
myAttachments(i).SaveAsFile mytempfolder & "\" & _
myAttachments(i).DisplayName
scenario = "doc"
Debug.Print scenario
End If
If ((extension = "zip") Or (extension = "ZIP")) Then
nbzip = nbzip + 1
Debug.Print nbzip
myzip = mytempfolder & "\" & myAttachments(i)
Debug.Print myzip
shellunzip = CheminWinZip & "\winzip32.exe -e"
Debug.Print shellunzip
myindex = i
Debug.Print myindex
tabzipfile(k) = myAttachments(i)
Debug.Print tabzipfile(k)
k = k + 1
Debug.Print k
'Listfile.AddItem myAttachments(i)
'Debug.Print myAttachments(i)
myAttachments(i).SaveAsFile mytempfolder & "\" & _
myAttachments(i).DisplayName
scenario = "zip"
Debug.Print scenario
End If
Next i
If (nbzip = 1) Then
'myshell = "Shell (" & shellunzip & " " & Chr(34) & myzip & Chr(34) & " " & Chr(34) & mytempfolder & Chr(34) & ")"
'Debug.Print myshell
'Shell (shellunzip & " " & Chr(34) & myzip & Chr(34) & " " & Chr(34) & mytempfolder & Chr(34))
Shell (CheminWinZip & "winzip32.exe -e """ & myzip & """ """ & mytempfolder & """")
fso.DeleteFile myzip, True
Call lister
End If
If (nbzip > 1) Then
For l = 0 To (k - 1)
Listfile.AddItem tabzipfile(l)
Debug.Print tabzipfile(l)
Next l
End If
End If
Next
nbattach = Listfile.ListCount
Debug.Print nbattach
For j = 0 To (nbattach - 1)
Debug.Print j
Debug.Print Listfile.Value
Listfile.Selected(j) = True
Next j
'----------------------------'
'Frmlistzip.Visible = False
'Frmlistfile.Visible = False
'Frmfile2zip.Visible = False
'btnpushfile.Visible = False
'btnremovefile.Visible = False
frmnamezip.Visible = False
btnproceed.Visible = False
choixrep.Visible = False
If scenario = "doc" Then
chkboxrename.Visible = False
Else
chkboxrename.Visible = True
End If
'----------------------------'
End Sub |