Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error (http://www.outlookbanter.com/outlook-vba/63365-redemption-insert-text-run-time.html)

JW December 17th 07 04:04 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the
selected email(s) and insert a list of the filenames removed at
the top of the message using the Redemption SafeMailItem and
SafeInspector objects. However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA debugger,
or if I display a message box before the line, i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the text
string to insert in the message

While olAttachments.Count 0
sText = sText & olAttachments(1).fileName
& vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments -
just create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText & olAttachments(i).fileName
& vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem,
sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------



Dmitry Streblechenko December 17th 07 10:26 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
When is that function called? Is the inspector already open and visible by
then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the selected
email(s) and insert a list of the filenames removed at the top of the
message using the Redemption SafeMailItem and SafeInspector objects.
However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA debugger, or if I
display a message box before the line, i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" & vbNewLine & " " &
vbNewLine

If removeAttachments Then

'Delete each attachment and create the text string to
insert in the message

While olAttachments.Count 0
sText = sText & olAttachments(1).fileName &
vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments - just create
the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText & olAttachments(i).fileName &
vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem, sText As
String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------





JW December 17th 07 11:49 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Hi,

It's called manually by me clicking Tools - Macro and running
Remove_Attachments.

When I run it, the only Outlook window open is the main Outlook
window.

Thanks,

"Dmitry Streblechenko" wrote in message
...
When is that function called? Is the inspector already open and
visible by then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the
selected email(s) and insert a list of the filenames removed
at the top of the message using the Redemption SafeMailItem
and SafeInspector objects. However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA
debugger, or if I display a message box before the line, i.e.
MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the text
string to insert in the message

While olAttachments.Count 0
sText = sText &
olAttachments(1).fileName & vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments -
just create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText &
olAttachments(i).fileName & vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem,
sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------







Dmitry Streblechenko December 18th 07 12:15 AM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Which is why Redemption returns an error - the inspector simply doesn ot
exist as a window when you call olSMailItem.GetInspector

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

It's called manually by me clicking Tools - Macro and running
Remove_Attachments.

When I run it, the only Outlook window open is the main Outlook window.

Thanks,

"Dmitry Streblechenko" wrote in message
...
When is that function called? Is the inspector already open and visible
by then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the selected
email(s) and insert a list of the filenames removed at the top of the
message using the Redemption SafeMailItem and SafeInspector objects.
However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA debugger, or if I
display a message box before the line, i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" & vbNewLine & " "
& vbNewLine

If removeAttachments Then

'Delete each attachment and create the text string to
insert in the message

While olAttachments.Count 0
sText = sText & olAttachments(1).fileName &
vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments - just
create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText & olAttachments(i).fileName &
vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem, sText As
String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------









JW December 18th 07 02:38 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
It isn't crashing at olSMailItem.GetInspector. It's crashing at
olSInsp.SelText = sText

In any case, I call olSMailItem.Display which opens the mail
message before inserting the text, so the inspector does exist as
a window when I call olSMailItem.GetInspector. I took your
question to mean what windows are open before running the macro.

I can examine olSMailItem in the debugger and all its properties
are there.

Why does it work successfully if I set a breakpoint at

olSInsp.SelText = sText

step through that one line in the debugger? And why does it work
if put MsgBox "" before the olSInsp.SelText line and run it
without breaking into the debugger? This looks like a timing
issue with automation objects to me. I know nothing about
automation so I'm just guessing here.

Any other thoughts/ideas would be much appreciated.

thanks,

"Dmitry Streblechenko" wrote in message
...
Which is why Redemption returns an error - the inspector simply
doesn ot exist as a window when you call
olSMailItem.GetInspector

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

It's called manually by me clicking Tools - Macro and running
Remove_Attachments.

When I run it, the only Outlook window open is the main
Outlook window.

Thanks,

"Dmitry Streblechenko" wrote in message
...
When is that function called? Is the inspector already open
and visible by then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from
the selected email(s) and insert a list of the filenames
removed at the top of the message using the Redemption
SafeMailItem and SafeInspector objects. However it crashes
at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA
debugger, or if I display a message box before the line,
i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the
text string to insert in the message

While olAttachments.Count 0
sText = sText &
olAttachments(1).fileName & vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete
attachments - just create the text string to insert in the
message

For i = 1 To olAttachments.Count
sText = sText &
olAttachments(i).fileName & vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As
Redemption.SafeMailItem, sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------











Dmitry Streblechenko December 19th 07 10:46 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Correct, the Inspector COM object exists, but hte window (HWND in Win32
language) either does not exist or is invisible by the time you set SelText.
Display is asynchronous, so calling it is not enough, you need to wait a bit
after calling it it.
Are you using the Word editor? Can you turn it off in Tools | Options | Mail
Format?
If you are using a built-in editor, Redemption won't need to search for a
window since inspectors expose the IOleWindow interface (Word editor window
does not).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
It isn't crashing at olSMailItem.GetInspector. It's crashing at
olSInsp.SelText = sText

In any case, I call olSMailItem.Display which opens the mail message
before inserting the text, so the inspector does exist as a window when I
call olSMailItem.GetInspector. I took your question to mean what windows
are open before running the macro.

I can examine olSMailItem in the debugger and all its properties are
there.

Why does it work successfully if I set a breakpoint at

olSInsp.SelText = sText

step through that one line in the debugger? And why does it work if put
MsgBox "" before the olSInsp.SelText line and run it without breaking into
the debugger? This looks like a timing issue with automation objects to
me. I know nothing about automation so I'm just guessing here.

Any other thoughts/ideas would be much appreciated.

thanks,

"Dmitry Streblechenko" wrote in message
...
Which is why Redemption returns an error - the inspector simply doesn ot
exist as a window when you call olSMailItem.GetInspector

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

It's called manually by me clicking Tools - Macro and running
Remove_Attachments.

When I run it, the only Outlook window open is the main Outlook window.

Thanks,

"Dmitry Streblechenko" wrote in message
...
When is that function called? Is the inspector already open and visible
by then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the
selected email(s) and insert a list of the filenames removed at the
top of the message using the Redemption SafeMailItem and SafeInspector
objects. However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA debugger, or if
I display a message box before the line, i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" & vbNewLine & "
" & vbNewLine

If removeAttachments Then

'Delete each attachment and create the text string
to insert in the message

While olAttachments.Count 0
sText = sText & olAttachments(1).fileName &
vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments - just
create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText & olAttachments(i).fileName &
vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem, sText
As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------













JW December 20th 07 01:43 PM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Yes, Outlook is using the Word 2003 editor. I turned it off as
you said, however exactly the same error still occurs at:

olSInsp.SelText = sText

Your mention of asynchronous gave me the idea of putting DoEvents
before that line and .....success!! It now inserts the text and
runs to completion.

One slight issue however, is that the inserted text is in the
same font as the first line of the email message. I will
research this problem and in the meantime if you know how to
insert the text or otherwise change its font so that it's always
in Arial 10 I would be very grateful. These emails are in HTML
format. Obviously this issue doesn't arise for plain text
emails.

Thanks for all your help.

"Dmitry Streblechenko" wrote in message
...
Correct, the Inspector COM object exists, but hte window (HWND
in Win32 language) either does not exist or is invisible by the
time you set SelText.
Display is asynchronous, so calling it is not enough, you need
to wait a bit after calling it it.
Are you using the Word editor? Can you turn it off in Tools |
Options | Mail Format?
If you are using a built-in editor, Redemption won't need to
search for a window since inspectors expose the IOleWindow
interface (Word editor window does not).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
It isn't crashing at olSMailItem.GetInspector. It's crashing
at olSInsp.SelText = sText

In any case, I call olSMailItem.Display which opens the mail
message before inserting the text, so the inspector does exist
as a window when I call olSMailItem.GetInspector. I took your
question to mean what windows are open before running the
macro.

I can examine olSMailItem in the debugger and all its
properties are there.

Why does it work successfully if I set a breakpoint at

olSInsp.SelText = sText

step through that one line in the debugger? And why does it
work if put MsgBox "" before the olSInsp.SelText line and run
it without breaking into the debugger? This looks like a
timing issue with automation objects to me. I know nothing
about automation so I'm just guessing here.

Any other thoughts/ideas would be much appreciated.

thanks,

"Dmitry Streblechenko" wrote in message
...
Which is why Redemption returns an error - the inspector
simply doesn ot exist as a window when you call
olSMailItem.GetInspector

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

It's called manually by me clicking Tools - Macro and
running Remove_Attachments.

When I run it, the only Outlook window open is the main
Outlook window.

Thanks,

"Dmitry Streblechenko" wrote in message
...
When is that function called? Is the inspector already open
and visible by then?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from
the selected email(s) and insert a list of the filenames
removed at the top of the message using the Redemption
SafeMailItem and SafeInspector objects. However it crashes
at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error
440)'.

The program works fine if I step through it in the VBA
debugger, or if I display a message box before the line,
i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the
text string to insert in the message

While olAttachments.Count 0
sText = sText &
olAttachments(1).fileName & vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete
attachments - just create the text string to insert in the
message

For i = 1 To olAttachments.Count
sText = sText &
olAttachments(i).fileName & vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As
Redemption.SafeMailItem, sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(,
5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------















JW December 21st 07 12:53 AM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
I've now got the olHTMLEditor part working, but the olRTFEditor
part (using Redemption RTFEditor) isn't inserting any text. This
case statement is arrived at when processing a message created
using Rich Text format (not using Word editor).

Here's the code:

Private Sub InsertLines(olSMailItem As Redemption.SafeMailItem,
sLines() As String)
Dim olEditButton As Office.CommandBarButton
Dim olSInsp As Redemption.SafeInspector
Dim olRTFEditor As Redemption.RTFEditor
Dim wdDoc As Word.Document 'Requires
Microsoft Word Object Library reference
Dim mDoc As MSHTML.HTMLDocument 'Requires
Microsoft HTML Object Library reference
Dim mElement As MSHTML.IHTMLElement

'On Error Resume Next

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

Select Case olSInsp.EditorType

Case olEditorHTML

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

DoEvents

Set mDoc = olSInsp.HTMLEditor
Set mElement = mDoc.Body.all(0)

mElement.insertAdjacentHTML "beforeBegin", _
"P style=""font-family: Arial; font-size: 10pt;
color: blue""" & _
Join(sLines, "BR") & _
"/P"

Case olEditorRTF

'-- This correctly inserts the text lines in default
font (Arial 10pt black), but I want them to be in
'-- Arial 10pt blue
'olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

'-- Therefore use Redemption RTFEditor
'-- This should insert the text lines in Arial 10pt
blue, but it doesn't insert any lines
Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.RTFSelText = Join(sLines, vbNewLine) & "
" & vbNewLine
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 12
olRTFEditor.SelAttributes.Color = vbBlue

Case olEditorText

olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

Case olEditorWord

'-- UNTESTED
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines,
vbNewLine) & " " & vbNewLine

Case Else

MsgBox "Unrecognised EditorType: " &
olSInsp.EditorType & vbNewLine & vbNewLine & _
"Unable to insert text in message"

End Select

End Sub


Any ideas why the RTFEditor code above isn't inserting any lines?

Also, how do I create email messages in olEditorWord format to
test that? So far the 3 types of message format (HTML, RTF and
Plain Text) I've been able to create are handled by their
respective case statements.

thanks,

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the
selected email(s) and insert a list of the filenames removed at
the top of the message using the Redemption SafeMailItem and
SafeInspector objects. However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA
debugger, or if I display a message box before the line, i.e.
MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the text
string to insert in the message

While olAttachments.Count 0
sText = sText &
olAttachments(1).fileName & vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments -
just create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText &
olAttachments(i).fileName & vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem,
sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------





Dmitry Streblechenko December 21st 07 06:01 AM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
Does it work if you replace DoEvents with MsgBox?
Is that using the Word editor or the builtin editor?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
I've now got the olHTMLEditor part working, but the olRTFEditor part
(using Redemption RTFEditor) isn't inserting any text. This case
statement is arrived at when processing a message created using Rich Text
format (not using Word editor).

Here's the code:

Private Sub InsertLines(olSMailItem As Redemption.SafeMailItem, sLines()
As String)
Dim olEditButton As Office.CommandBarButton
Dim olSInsp As Redemption.SafeInspector
Dim olRTFEditor As Redemption.RTFEditor
Dim wdDoc As Word.Document 'Requires Microsoft Word
Object Library reference
Dim mDoc As MSHTML.HTMLDocument 'Requires Microsoft HTML
Object Library reference
Dim mElement As MSHTML.IHTMLElement

'On Error Resume Next

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

Select Case olSInsp.EditorType

Case olEditorHTML

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

DoEvents

Set mDoc = olSInsp.HTMLEditor
Set mElement = mDoc.Body.all(0)

mElement.insertAdjacentHTML "beforeBegin", _
"P style=""font-family: Arial; font-size: 10pt; color:
blue""" & _
Join(sLines, "BR") & _
"/P"

Case olEditorRTF

'-- This correctly inserts the text lines in default font
(Arial 10pt black), but I want them to be in
'-- Arial 10pt blue
'olSInsp.SelText = Join(sLines, vbNewLine) & " " & vbNewLine

'-- Therefore use Redemption RTFEditor
'-- This should insert the text lines in Arial 10pt blue, but
it doesn't insert any lines
Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.RTFSelText = Join(sLines, vbNewLine) & " " &
vbNewLine
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 12
olRTFEditor.SelAttributes.Color = vbBlue

Case olEditorText

olSInsp.SelText = Join(sLines, vbNewLine) & " " & vbNewLine

Case olEditorWord

'-- UNTESTED
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines, vbNewLine) & " "
& vbNewLine

Case Else

MsgBox "Unrecognised EditorType: " & olSInsp.EditorType &
vbNewLine & vbNewLine & _
"Unable to insert text in message"

End Select

End Sub


Any ideas why the RTFEditor code above isn't inserting any lines?

Also, how do I create email messages in olEditorWord format to test that?
So far the 3 types of message format (HTML, RTF and Plain Text) I've been
able to create are handled by their respective case statements.

thanks,

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from the selected
email(s) and insert a list of the filenames removed at the top of the
message using the Redemption SafeMailItem and SafeInspector objects.
However it crashes at the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA debugger, or if I
display a message box before the line, i.e. MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" & vbNewLine & " "
& vbNewLine

If removeAttachments Then

'Delete each attachment and create the text string to
insert in the message

While olAttachments.Count 0
sText = sText & olAttachments(1).fileName &
vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments - just create
the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText & olAttachments(i).fileName &
vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As Redemption.SafeMailItem, sText As
String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------







JW December 21st 07 11:32 AM

Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error
 
As I said, the case where olSInsp.EditorType = olEditorHTML is
working, so your question about replacing DoEvents in that part
of the code doesn't really apply. It's when VBA thinks the
EditorType is olEditorRTF and that part of the code is executed
that no lines are being inserted.

The messages are created in Rich Text format using the built-in
editor.

"Dmitry Streblechenko" wrote in message
...
Does it work if you replace DoEvents with MsgBox?
Is that using the Word editor or the builtin editor?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"JW" wrote in message
...
I've now got the olHTMLEditor part working, but the
olRTFEditor part (using Redemption RTFEditor) isn't inserting
any text. This case statement is arrived at when processing a
message created using Rich Text format (not using Word
editor).

Here's the code:

Private Sub InsertLines(olSMailItem As
Redemption.SafeMailItem, sLines() As String)
Dim olEditButton As Office.CommandBarButton
Dim olSInsp As Redemption.SafeInspector
Dim olRTFEditor As Redemption.RTFEditor
Dim wdDoc As Word.Document 'Requires
Microsoft Word Object Library reference
Dim mDoc As MSHTML.HTMLDocument 'Requires
Microsoft HTML Object Library reference
Dim mElement As MSHTML.IHTMLElement

'On Error Resume Next

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

Select Case olSInsp.EditorType

Case olEditorHTML

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

DoEvents

Set mDoc = olSInsp.HTMLEditor
Set mElement = mDoc.Body.all(0)

mElement.insertAdjacentHTML "beforeBegin", _
"P style=""font-family: Arial; font-size:
10pt; color: blue""" & _
Join(sLines, "BR") & _
"/P"

Case olEditorRTF

'-- This correctly inserts the text lines in
default font (Arial 10pt black), but I want them to be in
'-- Arial 10pt blue
'olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

'-- Therefore use Redemption RTFEditor
'-- This should insert the text lines in Arial 10pt
blue, but it doesn't insert any lines
Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.RTFSelText = Join(sLines, vbNewLine) &
" " & vbNewLine
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 12
olRTFEditor.SelAttributes.Color = vbBlue

Case olEditorText

olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

Case olEditorWord

'-- UNTESTED
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines,
vbNewLine) & " " & vbNewLine

Case Else

MsgBox "Unrecognised EditorType: " &
olSInsp.EditorType & vbNewLine & vbNewLine & _
"Unable to insert text in message"

End Select

End Sub


Any ideas why the RTFEditor code above isn't inserting any
lines?

Also, how do I create email messages in olEditorWord format to
test that? So far the 3 types of message format (HTML, RTF and
Plain Text) I've been able to create are handled by their
respective case statements.

thanks,

"JW" wrote in message
...
Hi,

Outlook 2003 SP3, Windows XP Pro SP2.

I've written the VBA code below to remove attachments from
the selected email(s) and insert a list of the filenames
removed at the top of the message using the Redemption
SafeMailItem and SafeInspector objects. However it crashes at
the line:

olSInsp.SelText = sText

With the error:

Run-time error '-2147467259 (80004005)':
Unspecified Error

If I then click Help it says 'Automation error (Error 440)'.

The program works fine if I step through it in the VBA
debugger, or if I display a message box before the line, i.e.
MsgBox ""

Any ideas where I'm going wrong and how to fix it?

Many thanks.

--------------- Start of code -----------------
Option Explicit

Sub Remove_Attachments()
Dim olMailItem As Outlook.MailItem
Dim olSMailItem As Redemption.SafeMailItem
Dim olAttachments As Outlook.Attachments
Dim sText As String
Dim i As Integer

Const removeAttachments As Boolean = False

Set olSMailItem = New Redemption.SafeMailItem

For Each olMailItem In ActiveExplorer.Selection

If olMailItem.Class = olMail Then

olSMailItem.Item = olMailItem
Set olAttachments = olSMailItem.Attachments

If olAttachments.Count 0 Then

sText = Now() & " removed attachments:" &
vbNewLine & " " & vbNewLine

If removeAttachments Then

'Delete each attachment and create the
text string to insert in the message

While olAttachments.Count 0
sText = sText &
olAttachments(1).fileName & vbNewLine
olAttachments(1).Delete
Wend

Else

'Testing only. Don't delete attachments -
just create the text string to insert in the message

For i = 1 To olAttachments.Count
sText = sText &
olAttachments(i).fileName & vbNewLine
Next
End If

olSMailItem.Display

InsertText olSMailItem, sText

olSMailItem.Close olSave

End If
End If
Next

End Sub

Private Sub InsertText(olSMailItem As
Redemption.SafeMailItem, sText As String)
Dim olSInsp As Redemption.SafeInspector
Dim olEditButton As Office.CommandBarButton

'On Error Resume Next

'Edit message

Set olEditButton =
Application.ActiveInspector.CommandBars.FindContro l(, 5604)
olEditButton.Execute

Set olSInsp = New Redemption.SafeInspector
olSInsp.Item = olSMailItem.GetInspector

'The next line crashes with:
' Run-time error '-2147467259 (80004005)':
' Unspecified Error
'Click Help and it says 'Automation error (Error 440)'
olSInsp.SelText = sText

Set olEditButton = Nothing
Set olSInsp = Nothing

End Sub
--------------- End of code -----------------










All times are GMT +1. The time now is 10:57 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com