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
| Public Sub OpenSharedMSG()
Dim OL As Object
If UCase(Application) = "OUTLOOK" Then
Set OL = Application
Else
Set OL = CreateObject("outlook.application")
End If
Dim oNamespace As OBJECT 'namespace
Dim oSharedItem As object 'MailItem
Dim oFolder As Object 'Folder
On Error GoTo ErrRoutine
' Get a reference to a NameSpace object.
Set oNamespace = OL.GetNamespace("MAPI")
' Open .msg.
Set oSharedItem = oNamespace.OpenSharedItem( _
"C:\temp\Mise à jour CRM.msg")
For each pj in osharedItem.attachments
pj.saveas &c:\temp \"& pj.filename
Next pj
EndRoutine:
On Error GoTo 0
Set oSharedItem = Nothing
Set oFolder = Nothing
Set oNamespace = Nothing
Exit Sub
ErrRoutine:
Select Case Err.Number
Case 287 ' &H0000011F
' This error occurs if the code is run by an
' untrusted application, and the user chose not to
' allow access.
MsgBox "Access to Outlook was denied by the user.", _
vbOKOnly, _
Err.Number & " - " & Err.Source
Case -2147024894 ' &H80070002
' Occurs if the specified file or URL could not
' be found, or the file or URL cannot be
' processed by the OpenSharedItem method.
MsgBox Err.Description, _
vbOKOnly, _
Err.Number & " - " & Err.Source
Case -2147352567 ' &H80020009
' Occurs if the specified file or URL is not valid,
' or you attempt to use the Move method on
' an Outlook item that represents a shared item.
MsgBox Err.Description, _
vbOKOnly, _
Err.Number & " - " & Err.Source
Case Else
' Any other error that may occur.
MsgBox Err.Description, _
vbOKOnly, _
Err.Number & " - " & Err.Source
End Select
GoTo EndRoutine
End Sub |
Partager