How to programaticaly use Bold or Colored Text in Task Body

B

bbnimda

Hi all,

I made a custom form "Task" and each time some one open the task I add at
the en of the Task body the time and the name of the curent user


I wanted to hihg light the Tag by making the the text Bold and colored
(one different color for each user)

Here is a part of my code
Function Item_Open()

Set FormPage = Item.GetInspector.ModifiedFormPages("MyForm")

CurUsr = application.GetNameSpace("MAPI").CurrentUser

body = body & CurUsr & " le " & date & chr(13) <= I want to make this line
Bold and Colored

....
....
end function


how can I do That
 
B

bbnimda

Hello Dimitry

I tryed but I got a message "This sample only works for the RTF Editor"
what's wrong ?

tks
 
K

Ken Slovak - [MVP - Outlook]

What code did you try? Did you instantiate an RTFEditor object and use that?
Is the item you tested on actually an RTF item?
 
B

bbnimda

I did nothing else than openning a new task and customise it and add script
to and some function
I saved my form and populate it in Public Folder (Excahnge 2003)

Q1: How can I set an RTF item
Q2: My form is in the "Public Folder" the RTF format will be available for
every user ?

tks
 
K

Ken Slovak - [MVP - Outlook]

A task item will have an RTF body. So what code did you use that gave you
the error? You didn't answer my question.
 
B

bbnimda

Dim CurUsr,YesNo,2Send,2Save,StampColor

Function Item_Open()
Set FormPage = Item.GetInspector.ModifiedFormPages("Tasks_ON")
Set Control = FormPage.Controls("ComboBox6")
Control.PossibleValues = "Normale;Haute"

CurUsr = application.GetNameSpace("MAPI").CurrentUser
Select case CurUsr
case "User1"
StampColor = 1

case "UserX"
StampColor = 1
end select
if len(body) = 0 then
body = & CurUsr & " " & date & chr(13)
else body = body & chr(13) & chr(13) & CurUsr & " " & date & chr(13)
end if
 
K

Ken Slovak - [MVP - Outlook]

That code doesn't use RTFEditor at all or even use Redemption at all. You
said the Redemption sample didn't work. So at this point I have no idea what
you're talking about.

If you want to change the format of the text you need to use Redemption
code, the RTFEditor object and format you're text correctly for RTF
formatting.
 
B

bbnimda

Sorry, O forgot to add a piece of code [ TXT buton function ]
I put the RTFEditor function in a button, because I still didn't found the
right sentence to use it the [ Function Item_Open() ]

1) I didn't found the way to apply the policy modification to the body task
2) the selected text became Bold and italic but stay black
3) I still get the message "This sample only works for the RTF Editor"



Sub TXT_click()

set sInspector = CreateObject("Redemption.SafeInspector")

sInspector.Item = Application.ActiveInspector

Set RTFEditor = sInspector.RTFEditor

RTFEditor.SelAttributes.Style.Bold = TRUE

RTFEditor.SelAttributes.Style.italic = TRUE

RTFEditor.SelAttributes.Color = 5

RTFEditor.SelAttributes.Color = 2

if (RTFEditor is Nothing) or (sInspector.EditorType <> olEditorRTF) Then

MsgBox "This sample only works for the RTF Editor" &vblf&
Item.GetInspector.EditorType

Else

RTFEditor.SelAttributes.Style.Bold = TRUE

End If

end sub
 
B

bbnimda

In fact my script was righ the only mistake I made is that at the end of
initialisation I added something like

"........
Body = Body & vblf
.......
"

at this point all my formated body Text (Bold / Color) became black and
standard (no bold or italic effect)

bbnimda said:
Sorry, O forgot to add a piece of code [ TXT buton function ]
I put the RTFEditor function in a button, because I still didn't found the
right sentence to use it the [ Function Item_Open() ]

1) I didn't found the way to apply the policy modification to the body
task
2) the selected text became Bold and italic but stay black
3) I still get the message "This sample only works for the RTF Editor"



Sub TXT_click()

set sInspector = CreateObject("Redemption.SafeInspector")

sInspector.Item = Application.ActiveInspector

Set RTFEditor = sInspector.RTFEditor

RTFEditor.SelAttributes.Style.Bold = TRUE

RTFEditor.SelAttributes.Style.italic = TRUE

RTFEditor.SelAttributes.Color = 5

RTFEditor.SelAttributes.Color = 2

if (RTFEditor is Nothing) or (sInspector.EditorType <> olEditorRTF) Then

MsgBox "This sample only works for the RTF Editor" &vblf&
Item.GetInspector.EditorType

Else

RTFEditor.SelAttributes.Style.Bold = TRUE

End If

end sub





Ken Slovak - said:
That code doesn't use RTFEditor at all or even use Redemption at all. You
said the Redemption sample didn't work. So at this point I have no idea
what you're talking about.

If you want to change the format of the text you need to use Redemption
code, the RTFEditor object and format you're text correctly for RTF
formatting.
 
K

Ken Slovak - [MVP - Outlook]

I didn't do the conversion from OLE_COLOR to RGB values but since black is
&H0 I'd imagine that 5 and 2 are just shades of black. Try setting the color
to something different like &HFF (or 255 which is red).

The message you're getting indicates from the applied test that RTFEditor is
either nothing or the editor type isn't RTF, that test really should be
before any attempts to use RTFEditor. What version of Outlook is this? Have
you tried using Item.GetInspector to set the SafeInspector.Item property
instead of using ActiveInspector?
 
B

bbnimda

Hello Ken

Here is my working code , If I do nothing else my formated text is kept
=================================
Function Item_Open()
Set myFolder = Application.ActiveExplorer.CurrentFolder
Id = myfolder.items.count
CurUsr = application.GetNameSpace("MAPI").CurrentUser
If Item.LastModificationTime <> #1/1/4501# Then
NewTask = 0
Long0 = 0
else
NewTask = 1
Long0 = len(body)
end if
If Not (Application.ActiveInspector Is Nothing) Then
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
Set RTFEd = sInspector.rtfeditor
If Not (RTFEd Is Nothing) Then
Set RTA = RTFEd.SelAttributes
RTFEd.SelStart = intStart + longueur
RTA.Style.Bold = True
RTA.Style.italic = true
RTA.Color = 9709060
if long0 > 0 then
sInspector.SelText = " " & vbLf & vbLf & vbLf & CurUsr & "
le "& date()& vbCrLf
else
sInspector.SelText = CurUsr & " "& date()& vbCrLf
end if
RTA.Style.Bold = false
RTA.Style.italic = false
RTA.Color = 1
end if
end if
End Function
=================================

but if I add something like
body = body & vblf&"closed " for example closed is added at the end of my
task body and all the task body text (include the text in bold or colored)
became simple text and black

tks for your help


Ken Slovak - said:
I didn't do the conversion from OLE_COLOR to RGB values but since black is
&H0 I'd imagine that 5 and 2 are just shades of black. Try setting the
color to something different like &HFF (or 255 which is red).

The message you're getting indicates from the applied test that RTFEditor
is either nothing or the editor type isn't RTF, that test really should be
before any attempts to use RTFEditor. What version of Outlook is this?
Have you tried using Item.GetInspector to set the SafeInspector.Item
property instead of using ActiveInspector?




bbnimda said:
Sorry, O forgot to add a piece of code [ TXT buton function ]
I put the RTFEditor function in a button, because I still didn't found
the right sentence to use it the [ Function Item_Open() ]

1) I didn't found the way to apply the policy modification to the body
task
2) the selected text became Bold and italic but stay black
3) I still get the message "This sample only works for the RTF Editor"



Sub TXT_click()

set sInspector = CreateObject("Redemption.SafeInspector")

sInspector.Item = Application.ActiveInspector

Set RTFEditor = sInspector.RTFEditor

RTFEditor.SelAttributes.Style.Bold = TRUE

RTFEditor.SelAttributes.Style.italic = TRUE

RTFEditor.SelAttributes.Color = 5

RTFEditor.SelAttributes.Color = 2

if (RTFEditor is Nothing) or (sInspector.EditorType <> olEditorRTF) Then

MsgBox "This sample only works for the RTF Editor" &vblf&
Item.GetInspector.EditorType

Else

RTFEditor.SelAttributes.Style.Bold = TRUE

End If

end sub
 
K

Ken Slovak - [MVP - Outlook]

You have to add what you want added using correct RTF formatting or else
you're rewriting the body as do add the new text. Add what you want using
RTFEditor.
 

Ask a Question

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

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

Ask a Question

Top