Crash with Redemption

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
 
S

Sue Mosher [MVP-Outlook]

You don't need Redemption to save attachments. Attachment.SaveAsFile never raises a security prompt.

You didn't say what error you're getting, but a common problem in saving files is that the file name is invalid or the target folder doesn't exist. I'd take a close look at the value used for strFile.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lars Ibsen

Dear Sue Mosher,
Thank you for your reply.
I know you are right when you say that Attachment.SaveAsFile never raises a
security prompt. You are the expert!
When I run my macro without the SafeMalItem I get a warning that says:
(translated from danish)
A program is trying to get access to emailaddresses saved in Outlook. Allow?
Yes or No.

Can you please tell me what raises this?

Best Regards
Lars

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
You don't need Redemption to save attachments. Attachment.SaveAsFile never
raises a security prompt.

You didn't say what error you're getting, but a common problem in saving
files is that the file name is invalid or the target folder doesn't exist.
I'd take a close look at the value used for strFile.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Unless you're creating an add-in for Outlook 2003, you'll get a security prompt when you access the Body or HTMLBody property. You can use Redemption to avoid that. Save the MailItem after you remove the attachments and then pass it to Redemption to finish the task by updating the body.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Lars Ibsen said:
Dear Sue Mosher,
Thank you for your reply.
I know you are right when you say that Attachment.SaveAsFile never raises a
security prompt. You are the expert!
When I run my macro without the SafeMalItem I get a warning that says:
(translated from danish)
A program is trying to get access to emailaddresses saved in Outlook. Allow?
Yes or No.

Can you please tell me what raises this?

Best Regards
Lars

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
You don't need Redemption to save attachments. Attachment.SaveAsFile never
raises a security prompt.

You didn't say what error you're getting, but a common problem in saving
files is that the file name is invalid or the target folder doesn't exist.
I'd take a close look at the value used for strFile.



Lars Ibsen said:
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
 
L

Lars Ibsen

Thank you very much!
Best Regards
Lars

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
Unless you're creating an add-in for Outlook 2003, you'll get a security
prompt when you access the Body or HTMLBody property. You can use Redemption
to avoid that. Save the MailItem after you remove the attachments and then
pass it to Redemption to finish the task by updating the body.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Lars Ibsen said:
Dear Sue Mosher,
Thank you for your reply.
I know you are right when you say that Attachment.SaveAsFile never raises
a
security prompt. You are the expert!
When I run my macro without the SafeMalItem I get a warning that says:
(translated from danish)
A program is trying to get access to emailaddresses saved in Outlook.
Allow?
Yes or No.

Can you please tell me what raises this?

Best Regards
Lars

"Sue Mosher [MVP-Outlook]" <[email protected]> skrev i en meddelelse
You don't need Redemption to save attachments. Attachment.SaveAsFile never
raises a security prompt.

You didn't say what error you're getting, but a common problem in saving
files is that the file name is invalid or the target folder doesn't exist.
I'd take a close look at the value used for strFile.



Lars Ibsen said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top