vba - Change background color of a word in richtextbox -


it's simple change color of entire richtextbox not on single word or character, there api or user control happens that. tried saving word doc rtf , copied item , pasted in rich text box , worked doesn't work well, how can done. hard or easy!

i once needed highlight text in richtextbox vb6 project along time ago.. , used following module (not written me)

module:

option explicit  public const lf_facesize = 32 public const wm_user = &h400 public const em_setcharformat = (wm_user + 68) public const cfm_backcolor = &h4000000 public const scf_selection = &h1  public declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd long, byval wmsg long, byval wparam long, lparam any) long  public type charformat2     cbsize integer    '2     wpad1 integer    '4     dwmask long    '8     dweffects long    '12     yheight long    '16     yoffset long    '20     crtextcolor long    '24     bcharset byte    '25     bpitchandfamily byte    '26     szfacename(0 lf_facesize - 1) byte    ' 58     wpad2 integer    ' 60  ' additional stuff supported richedit20     wweight integer    ' /* font weight (logfont value)      */     sspacing integer    ' /* amount space between letters  */     crbackcolor long    ' /* background color                 */     llcid long    ' /* locale id                        */     dwreserved long    ' /* reserved. must 0              */     sstyle integer    ' /* style handle                     */     wkerning integer    ' /* twip size above kern char pair*/     bunderlinetype byte    ' /* underline type                   */     banimation byte    ' /* animated text marching ants */     brevauthor byte    ' /* revision author index            */     breserved1 byte end type 

call:

to highlight selected text yellow color

dim rtfformat charformat2 rtfformat     .cbsize = len(rtfformat)     .dwmask = cfm_backcolor     .crbackcolor = vbyellow end sendmessage richtextbox1.hwnd, em_setcharformat, scf_selection, rtfformat 

hope helps :)


Comments