A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old December 21st 07, 04:54 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does not, right?
Are you sure you have a valid RTF string? What is it? I do not see where you
set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText, then just apply
the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------










Ads
  #12  
Old December 21st 07, 08:02 PM posted to microsoft.public.outlook.program_vba
JW
external usenet poster
 
Posts: 9
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because it
seemed logical that RTFSelText goes with the RTFEditor, and the
one bit of example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now! Although you
say set olSInsp.SelText and then apply the formatting, it only
works if I do the opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using Redemption
RTFEditor and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

sLines is an array of strings passed into this subroutine from
Remove_Attachments, similar to the subroutine I originally
posted. The strings just contain normal printable ASCII
characters - nothing fancy, no embedded control characters etc.

Does anyone know how to create an email message so that I can
test the case where olSInsp.EditorType = olEditorWord? So far
all the messages I've created using different combinations of the
compose message format (HTML, RTF or plain text) and the Outlook
editor (Word 2003 or built-in editor) are trapped by either
olEditorHTML, olEditorRTF or olEditorText. I want to ensure that
my program works correctly regardless of the email message format
or the user's Outlook - Tools - Options - Mail Format settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does
not, right?
Are you sure you have a valid RTF string? What is it? I do not
see where you set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText,
then just apply the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------












  #13  
Old December 21st 07, 11:04 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

You can check if SafeInspector.WordEditor is not null, and use it regardless
of anything else.

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

"JW" wrote in message
...
Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because it seemed
logical that RTFSelText goes with the RTFEditor, and the one bit of
example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now! Although you say set
olSInsp.SelText and then apply the formatting, it only works if I do the
opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using Redemption RTFEditor
and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " & vbNewLine

sLines is an array of strings passed into this subroutine from
Remove_Attachments, similar to the subroutine I originally posted. The
strings just contain normal printable ASCII characters - nothing fancy, no
embedded control characters etc.

Does anyone know how to create an email message so that I can test the
case where olSInsp.EditorType = olEditorWord? So far all the messages
I've created using different combinations of the compose message format
(HTML, RTF or plain text) and the Outlook editor (Word 2003 or built-in
editor) are trapped by either olEditorHTML, olEditorRTF or olEditorText.
I want to ensure that my program works correctly regardless of the email
message format or the user's Outlook - Tools - Options - Mail Format
settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does not, right?
Are you sure you have a valid RTF string? What is it? I do not see where
you set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText, then just
apply the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------














  #14  
Old December 22nd 07, 04:23 PM posted to microsoft.public.outlook.program_vba
JW
external usenet poster
 
Posts: 9
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

Do you mean like:

If Not olSInsp.WordEditor Is Nothing Then
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines, vbNewLine)
& " " & vbNewLine
End If

The trouble is, olSInsp.WordEditor is always nothing, in the same
way that olSInsp.EditorType is never olEditorWord.

"Dmitry Streblechenko" wrote in message
...
You can check if SafeInspector.WordEditor is not null, and use
it regardless of anything else.

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

"JW" wrote in message
...
Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because
it seemed logical that RTFSelText goes with the RTFEditor, and
the one bit of example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now! Although
you say set olSInsp.SelText and then apply the formatting, it
only works if I do the opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using
Redemption RTFEditor and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

sLines is an array of strings passed into this subroutine from
Remove_Attachments, similar to the subroutine I originally
posted. The strings just contain normal printable ASCII
characters - nothing fancy, no embedded control characters
etc.

Does anyone know how to create an email message so that I can
test the case where olSInsp.EditorType = olEditorWord? So far
all the messages I've created using different combinations of
the compose message format (HTML, RTF or plain text) and the
Outlook editor (Word 2003 or built-in editor) are trapped by
either olEditorHTML, olEditorRTF or olEditorText. I want to
ensure that my program works correctly regardless of the email
message format or the user's Outlook - Tools - Options - Mail
Format settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does
not, right?
Are you sure you have a valid RTF string? What is it? I do
not see where you set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText,
then just apply the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------
















  #15  
Old December 22nd 07, 06:48 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

Even if you turn the Word editor on in Tools | Options?

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

"JW" wrote in message
...
Do you mean like:

If Not olSInsp.WordEditor Is Nothing Then
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines, vbNewLine) & " " &
vbNewLine
End If

The trouble is, olSInsp.WordEditor is always nothing, in the same way that
olSInsp.EditorType is never olEditorWord.

"Dmitry Streblechenko" wrote in message
...
You can check if SafeInspector.WordEditor is not null, and use it
regardless of anything else.

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

"JW" wrote in message
...
Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because it seemed
logical that RTFSelText goes with the RTFEditor, and the one bit of
example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now! Although you say
set olSInsp.SelText and then apply the formatting, it only works if I do
the opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using Redemption
RTFEditor and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " & vbNewLine

sLines is an array of strings passed into this subroutine from
Remove_Attachments, similar to the subroutine I originally posted. The
strings just contain normal printable ASCII characters - nothing fancy,
no embedded control characters etc.

Does anyone know how to create an email message so that I can test the
case where olSInsp.EditorType = olEditorWord? So far all the messages
I've created using different combinations of the compose message format
(HTML, RTF or plain text) and the Outlook editor (Word 2003 or built-in
editor) are trapped by either olEditorHTML, olEditorRTF or olEditorText.
I want to ensure that my program works correctly regardless of the email
message format or the user's Outlook - Tools - Options - Mail Format
settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does not,
right?
Are you sure you have a valid RTF string? What is it? I do not see
where you set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText, then just
apply the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------


















  #16  
Old December 22nd 07, 06:56 PM posted to microsoft.public.outlook.program_vba
JW
external usenet poster
 
Posts: 9
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

Yes. As I said, all combinations of message format and editor
don't produce an olEditorWord.

"Dmitry Streblechenko" wrote in message
...
Even if you turn the Word editor on in Tools | Options?

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

"JW" wrote in message
...
Do you mean like:

If Not olSInsp.WordEditor Is Nothing Then
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines,
vbNewLine) & " " & vbNewLine
End If

The trouble is, olSInsp.WordEditor is always nothing, in the
same way that olSInsp.EditorType is never olEditorWord.

"Dmitry Streblechenko" wrote in message
...
You can check if SafeInspector.WordEditor is not null, and
use it regardless of anything else.

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

"JW" wrote in message
...
Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because
it seemed logical that RTFSelText goes with the RTFEditor,
and the one bit of example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now!
Although you say set olSInsp.SelText and then apply the
formatting, it only works if I do the opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using
Redemption RTFEditor and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " &
vbNewLine

sLines is an array of strings passed into this subroutine
from Remove_Attachments, similar to the subroutine I
originally posted. The strings just contain normal
printable ASCII characters - nothing fancy, no embedded
control characters etc.

Does anyone know how to create an email message so that I
can test the case where olSInsp.EditorType = olEditorWord?
So far all the messages I've created using different
combinations of the compose message format (HTML, RTF or
plain text) and the Outlook editor (Word 2003 or built-in
editor) are trapped by either olEditorHTML, olEditorRTF or
olEditorText. I want to ensure that my program works
correctly regardless of the email message format or the
user's Outlook - Tools - Options - Mail Format settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText
does not, right?
Are you sure you have a valid RTF string? What is it? I do
not see where you set it in your code.
Why are you setting RTFSelText? You can set
olSInsp.SelText, then just apply the formatting like you
already do.

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

"JW" wrote in message
...
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 -----------------




















  #17  
Old December 22nd 07, 10:26 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Redemption insert text - Run-time error '-2147467259 (80004005)' Unspecified Error

You don't need to read the EditorType property. As long as WordEditor is not
null, you should be eable to use the Word Object Model to manipulate the
text.

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

"JW" wrote in message
...
Yes. As I said, all combinations of message format and editor don't
produce an olEditorWord.

"Dmitry Streblechenko" wrote in message
...
Even if you turn the Word editor on in Tools | Options?

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

"JW" wrote in message
...
Do you mean like:

If Not olSInsp.WordEditor Is Nothing Then
Set wdDoc = olSInsp.WordEditor
wdDoc.Characters(1).InsertBefore Join(sLines, vbNewLine) & " " &
vbNewLine
End If

The trouble is, olSInsp.WordEditor is always nothing, in the same way
that olSInsp.EditorType is never olEditorWord.

"Dmitry Streblechenko" wrote in message
...
You can check if SafeInspector.WordEditor is not null, and use it
regardless of anything else.

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

"JW" wrote in message
...
Hi Dmitry,

I thought I had to use RTFSelText instead of SelText because it seemed
logical that RTFSelText goes with the RTFEditor, and the one bit of
example code from you I found at

http://groups.google.com/group/micro...40f1f6a7e188d8

also shows that.

But thanks to another clue this part's working now! Although you say
set olSInsp.SelText and then apply the formatting, it only works if I
do the opposite.

Code:

Case olEditorRTF

'Must set the text attributes first using Redemption
RTFEditor and then insert the text

Set olRTFEditor = olSInsp.RTFEditor
olRTFEditor.SelAttributes.Name = "Arial"
olRTFEditor.SelAttributes.Size = 10
olRTFEditor.SelAttributes.Color = vbBlue
olSInsp.SelText = Join(sLines, vbNewLine) & " " & vbNewLine

sLines is an array of strings passed into this subroutine from
Remove_Attachments, similar to the subroutine I originally posted.
The strings just contain normal printable ASCII characters - nothing
fancy, no embedded control characters etc.

Does anyone know how to create an email message so that I can test the
case where olSInsp.EditorType = olEditorWord? So far all the messages
I've created using different combinations of the compose message
format (HTML, RTF or plain text) and the Outlook editor (Word 2003 or
built-in editor) are trapped by either olEditorHTML, olEditorRTF or
olEditorText. I want to ensure that my program works correctly
regardless of the email message format or the user's Outlook - Tools -
Options - Mail Format settings.

Thanks again,

"Dmitry Streblechenko" wrote in message
...
Ok, so olSInsp.SelText works, but olRTFEditor.RTFSelText does not,
right?
Are you sure you have a valid RTF string? What is it? I do not see
where you set it in your code.
Why are you setting RTFSelText? You can set olSInsp.SelText, then
just apply the formatting like you already do.

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

"JW" wrote in message
...
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 -----------------






















 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 80004005 On Starting Outlook dmpavlis Outlook Express 4 February 28th 07 09:31 PM
error code 80004005 4 months now dwolf Outlook Express 19 February 27th 07 01:30 AM
error code 80004005 4 months now hayat Outlook Express 0 February 2nd 07 03:16 PM
Outlook Express error 80004005 chasse//casse.700250amp Outlook Express 7 January 22nd 06 03:31 AM
Unspecified Error Laron Street Outlook - General Queries 1 January 10th 06 05:28 AM


All times are GMT +1. The time now is 12:30 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.