Word VBA: Have any character styles been assigned within the selection? -
is there simple , universal way find out whether or not character style has been assigned within selected text? presently i'm using function, not independent of ms word language version:
function anycharacterstyleassigned() 'elicit name of default paragraph font v_applang = application.language if v_applang = 1031 vst_default = "absatz-standardschriftart" elseif v_applang = 1045 vst_default = "domy" & chrw(347) & "lna czcionka akapitu" elseif v_applan = 1033 vst_default = "default paragraph font" else msgbox prompt:="this script doesn't work language version of word", buttons:=vbokonly end end if 'search default paragraph font within selection range set r_range = selection.range r_range.find.clearformatting r_range.find.style = vst_default r_range.find.execute findtext:="", forward:=true, wrap:=wdfindstop, format:=true anycharacterstyleassigned = iif(r_range.start >= selection.end, false, true) end function
a better test following. code have, if selection doesn't have style, selection never changes, have true case.
public sub styletest() dim r_range range set r_range = selection.range r_range.find.clearformatting r_range.find.style = "strong" dim anycharacterstyleassigned boolean anycharacterstyleassigned = false if r_range.find.execute(forward:=true, wrap:=wdfindstop, format:=true) = true r_range.select anycharacterstyleassigned = true end if end sub
Comments
Post a Comment