How to add set text bold, italic, super script and sub script in comment text in Word VBA? -


i want format comment text in word template using vba. can add simple text using following code. don't know how format text

commenttext = "test bold: bold text & vbnewline & test italic: italic text & vbnewline & test bold italic: bold italic text & vbnewline &  test superscript: brandtm & vbnewline & test subscript: h2o" selection.comments.add range:=selection.range selection         .typetext (commenttext)                        'add comment text end 

output should following image: enter image description here

the code below add formatted comment selected text. tested in word 2007, , functioning expected.

by way, in case need similar in future, start recording macro, add comment, stop recording. resulting macro code should of way there.

public sub addcomment()    selection.comments.add range:=selection.range    selection     .typeparagraph      .typetext text:="test bold: bold text"     .moveleft unit:=wdcharacter, count:=9, extend:=wdextend     .font.bold = wdtoggle     .endkey unit:=wdline     .font.bold = wdtoggle      .typeparagraph      .typetext text:="test italic: italic text"     .moveleft unit:=wdcharacter, count:=11, extend:=wdextend     .font.italic = wdtoggle     .endkey unit:=wdline     .font.italic = wdtoggle      .typeparagraph      .typetext text:="test bold italic: bold italic text"     .moveleft unit:=wdcharacter, count:=16, extend:=wdextend     .font.bold = wdtoggle     .font.italic = wdtoggle     .endkey unit:=wdline     .font.italic = wdtoggle     .font.bold = wdtoggle      .typeparagraph      .typetext text:="test superscript: brandtm"     .moveleft unit:=wdcharacter, count:=2, extend:=wdextend     .font.superscript = true     .endkey unit:=wdline     .font.superscript = false      .typeparagraph      .typetext text:="test subscript: h20"     .moveleft unit:=wdcharacter, count:=1     .moveleft unit:=wdcharacter, count:=1, extend:=wdextend     .font.subscript = true     .endkey unit:=wdline     .font.subscript = false   end  end sub 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -