L
Lars Ibsen
Hello,
I am trying to rewrite a macro to save attachments without the security
prompt, using Redemption.
My Outlook crashes at:
objAttachments.Item(i).SaveAsFile strFile
Does anyone know why this is happening?
Here is the macro:
Option Explicit
Public Sub GemBlandetKopi()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objSMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
'Destinationmappe
strFolderpath = "C:\Documents and Settings\Lars\Dokumenter\Email
Vedhæftninger"
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = strFolderpath & "\Blandet\"
For Each objMsg In objSelection
Set objSMsg = CreateObject("Redemption.SafeMailItem")
objSMsg.Item = objMsg
Set objAttachments = objSMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFile = InputBox(strFolderpath & Chr(10) & Chr(10) & _
"Gem vedhæftning(er) som:", "Gem vedhæftning.", strFile)
If strFile = vbNullString Then
Exit Sub
Else
strFile = strFolderpath & strFile
End If
objAttachments.Item(i).SaveAsFile strFile
objAttachments.Item(i).Delete
'check for html and use html tags in link
If objMsg.BodyFormat <> olFormatHTML Then
strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
Else
strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
strFile & "'>" & strFile & "</a>"
End If
Next i
If objMsg.BodyFormat <> olFormatHTML Then
objMsg.Body = objMsg.Body & vbCrLf & _
"Vedhæftning gemt som: " & strDeletedFiles
Else
objMsg.HTMLBody = objMsg.HTMLBody & "<p>" & _
"Vedhæftning gemt som: " & strDeletedFiles
End If
objMsg.Save
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
Set objSMsg = Nothing
End Sub
Best Regards
Lars
I am trying to rewrite a macro to save attachments without the security
prompt, using Redemption.
My Outlook crashes at:
objAttachments.Item(i).SaveAsFile strFile
Does anyone know why this is happening?
Here is the macro:
Option Explicit
Public Sub GemBlandetKopi()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objSMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
'Destinationmappe
strFolderpath = "C:\Documents and Settings\Lars\Dokumenter\Email
Vedhæftninger"
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = strFolderpath & "\Blandet\"
For Each objMsg In objSelection
Set objSMsg = CreateObject("Redemption.SafeMailItem")
objSMsg.Item = objMsg
Set objAttachments = objSMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFile = InputBox(strFolderpath & Chr(10) & Chr(10) & _
"Gem vedhæftning(er) som:", "Gem vedhæftning.", strFile)
If strFile = vbNullString Then
Exit Sub
Else
strFile = strFolderpath & strFile
End If
objAttachments.Item(i).SaveAsFile strFile
objAttachments.Item(i).Delete
'check for html and use html tags in link
If objMsg.BodyFormat <> olFormatHTML Then
strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
Else
strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _
strFile & "'>" & strFile & "</a>"
End If
Next i
If objMsg.BodyFormat <> olFormatHTML Then
objMsg.Body = objMsg.Body & vbCrLf & _
"Vedhæftning gemt som: " & strDeletedFiles
Else
objMsg.HTMLBody = objMsg.HTMLBody & "<p>" & _
"Vedhæftning gemt som: " & strDeletedFiles
End If
objMsg.Save
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
Set objSMsg = Nothing
End Sub
Best Regards
Lars