#1
|
|||
|
|||
character style
Here I have attached a word file.
While run a macro need to create character styles. |
#2
|
||||
|
||||
So what have you tried? There are plenty of code examples here for how to process table content, as well as for how to create Styles.
In any event, one wouldn't simply create such a set of Styles (some of which are already defined in Word) conditionally for any given document - one would simply create all the required Styles once in the relevant document template.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I just tried for the other style I unable to do others. Kindly help me on this
Options.DefaultHighlightColorIndex = wdYellow
Selection.Find.ClearFormatting With Selection.Find.Font .Bold = True .Italic = True .Superscript = False .Subscript = False End With Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Highlight = True Selection.Find.Replacement.Style = ActiveDocument.Styles("cBI") With Selection.Find.Replacement.Font .Bold = False .Italic = False .Superscript = False .Subscript = False End With With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll |
#4
|
||||
|
||||
Your first post says:
Your second post has nothing at all to do with creating styles. Rather, it appears you're trying to apply some existing Styles, which is entirely different. In any event, it doesn't look to me like you've done anything more than play around with the macro recorder.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Yes I used macro recorder only
Kindly guide me to in this.
|
#6
|
||||
|
||||
Here is the code to do the non-Greek and non-operator content. I'll leave it to you to do the rest.
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "[!\<-\>\^÷" & AscW(&H374) & "-" & AscW(&H3E1) & _ AscW(&H2C2) & "-" & AscW(&H2C7) & _ AscW(&H1F00) & "-" & AscW(&H1FEE) & _ AscW(&H2044) & "-" & AscW(&H208E) & _ AscW(&H2202) & "-" & AscW(&H2265) & "]" .Replacement.Text = "" .MatchWildcards = True .Format = True .Forward = True .Wrap = wdFindContinue .Font.Bold = False .Font.Italic = True .Font.Subscript = False .Font.Superscript = False .Replacement.Style = "cItalic" .Execute Replace:=wdReplaceAll .Font.Subscript = True .Font.Superscript = False .Replacement.Style = "cIsub" .Execute Replace:=wdReplaceAll .Font.Subscript = False .Font.Superscript = True .Replacement.Style = "cIsup" .Execute Replace:=wdReplaceAll .Font.Bold = True .Font.Italic = False .Font.Subscript = False .Font.Superscript = False .Replacement.Style = "cBold" .Execute Replace:=wdReplaceAll .Font.Subscript = True .Font.Superscript = False .Replacement.Style = "cBsub" .Execute Replace:=wdReplaceAll .Font.Subscript = False .Font.Superscript = True .Replacement.Style = "cBsup" .Execute Replace:=wdReplaceAll .Font.Bold = True .Font.Italic = True .Font.Subscript = False .Font.Superscript = False .Replacement.Style = "cBI" .Execute Replace:=wdReplaceAll .Font.Subscript = True .Font.Superscript = False .Replacement.Style = "cBIsub" .Execute Replace:=wdReplaceAll .Font.Subscript = False .Font.Superscript = True .Replacement.Style = "cBIsup" .Execute Replace:=wdReplaceAll .Font.Bold = False .Font.Italic = False .Font.Subscript = True .Font.Superscript = False .Replacement.Style = "cSub" .Execute Replace:=wdReplaceAll .Font.Subscript = False .Font.Superscript = True .Replacement.Style = "cSup" .Execute Replace:=wdReplaceAll .ClearFormatting .Font.AllCaps = True .Font.SmallCaps = False .Replacement.Style = "cAllCaps" .Execute Replace:=wdReplaceAll .Font.AllCaps = False .Font.SmallCaps = True .Replacement.Style = "cSmCap" .Execute Replace:=wdReplaceAll End With End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
I tried the code
In the attached document.
Its stops here .Replacement.Style = "cItalic" |
#8
|
||||
|
||||
That would only be because your document lacks the 'cItalic' Style. It's your responsibility to make sure the Styles exist...
I refer you again to what is said in post #2: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thanks
I add the below code and work fine now.
Dim objDoc As Document Dim cBI As Style, cBIsub As Style, cBIsup As Style, cItalic As Style, cIsub As Style, cIsup As Style, cBold As Style, cBsub As Style, cBsup As Style, cSub As Style, cSup As Style, cAllCap As Style, cSmCap As Style Set objDoc = ActiveDocument Set cBI = ActiveDocument.Styles.Add("cBI", Type:=WdStyleType.wdStyleTypeCharacter) Set cBIsub = ActiveDocument.Styles.Add("cBIsub", Type:=WdStyleType.wdStyleTypeCharacter) Set cBIsup = ActiveDocument.Styles.Add("cBIsup", Type:=WdStyleType.wdStyleTypeCharacter) Set cBold = ActiveDocument.Styles.Add("cBold", Type:=WdStyleType.wdStyleTypeCharacter) Set cBsub = ActiveDocument.Styles.Add("cBsub", Type:=WdStyleType.wdStyleTypeCharacter) Set cBsup = ActiveDocument.Styles.Add("cBsup", Type:=WdStyleType.wdStyleTypeCharacter) Set cItalic = ActiveDocument.Styles.Add("cItalic", Type:=WdStyleType.wdStyleTypeCharacter) Set cIsub = ActiveDocument.Styles.Add("cIsub", Type:=WdStyleType.wdStyleTypeCharacter) Set cIsup = ActiveDocument.Styles.Add("cIsup", Type:=WdStyleType.wdStyleTypeCharacter) Set cSub = ActiveDocument.Styles.Add("cSub", Type:=WdStyleType.wdStyleTypeCharacter) Set cSup = ActiveDocument.Styles.Add("cSup", Type:=WdStyleType.wdStyleTypeCharacter) Set cAllCap = ActiveDocument.Styles.Add("cAllCap", Type:=WdStyleType.wdStyleTypeCharacter) Set cSmCap = ActiveDocument.Styles.Add("cSmCap", Type:=WdStyleType.wdStyleTypeCharacter) and Help me how to find greek letters. I will do the remaining. |
#10
|
||||
|
||||
That's all very well, but all you've done is add some Style names. You haven't told Word anything about what attributes this Styles have (e.g. italic, bold, superscript, subscript, etc.).
The wildcard Find expression in the macro I posted shows you how to exclude Greek and operator content. All you need do is modify that to find just the Greek content.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
I have no Idea.
Unable to find Greek characters.
But I did the attributes as below for others also. Set cBI = ActiveDocument.Styles.Add("cBI", Type:=WdStyleType.wdStyleTypeCharacter) With cBI.Font .Bold = True .Italic = True .Subscript = False .Superscript = False .ColorIndex = wdBrightGreen End With and I tried for a single greek but not find and change. Selection.Find.Replacement.Font.Name = "Times New Roman" With Selection.Find .Text = ChrW(61508) .Replacement.Text = "\Delta;" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With |
#12
|
||||
|
||||
Hardly surprising - ChrW(61508) doesn't return a greek character...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Kindly look
In the below url and attached Screenshot.
Private Use Area (U+E000 - U+F8FF) - Test for Unicode support in Web browsers |
#14
|
||||
|
||||
The code I posted shows the correct way to refer to unicode characters - it even includes all the character ranges of concern!!!
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
||||
|
||||
Because your searches overlap, I would make use of the previous searches to simplify the Greek/Operator code
First Round: do the searches regardless of the characters Second Round (Greek): Find Greek characters and then work out what character style is applied and append 'Greek' to the character style Third Round (Math): Find Math characters and then work out what character style is applied and append 'Math' to the character style
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Style type character continues on to new paragraph | myalo | Word | 6 | 02-07-2021 02:56 PM |
Automatically applying character style while using fast style feature | Didier Super | Word | 1 | 04-10-2017 05:10 AM |
Tab character causes style change to Heading 4 after macro | Jennifer Murphy | Word VBA | 2 | 12-14-2015 02:31 AM |
Change the leading of a character style??? | Char t | Word | 1 | 11-05-2011 01:18 PM |
Character style stripped while applying paragraph style | sams_gates | Word | 0 | 08-29-2009 02:03 AM |