Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2021, 10:36 PM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default character style

Here I have attached a word file.



While run a macro need to create character styles.
Attached Files
File Type: docx CharacterStyle.docx (12.5 KB, 15 views)
Reply With Quote
  #2  
Old 05-14-2021, 09:35 PM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 05-14-2021, 09:39 PM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default 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
Reply With Quote
  #4  
Old 05-14-2021, 10:56 PM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your first post says:
Quote:
Originally Posted by balavaka View Post
While run a macro need to create character styles.
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]
Reply With Quote
  #5  
Old 05-14-2021, 11:01 PM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default Yes I used macro recorder only

Kindly guide me to in this.
Reply With Quote
  #6  
Old 05-14-2021, 11:53 PM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 05-15-2021, 01:14 AM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default I tried the code

In the attached document.

Its stops here

.Replacement.Style = "cItalic"
Attached Files
File Type: docx Sample Doc.docx (14.6 KB, 5 views)
Reply With Quote
  #8  
Old 05-15-2021, 01:16 AM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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:
Originally Posted by macropod View Post
There are plenty of code examples here 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]
Reply With Quote
  #9  
Old 05-15-2021, 01:59 AM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default 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.
Reply With Quote
  #10  
Old 05-15-2021, 02:07 AM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #11  
Old 05-15-2021, 07:42 AM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default 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
Reply With Quote
  #12  
Old 05-15-2021, 02:34 PM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hardly surprising - ChrW(61508) doesn't return a greek character...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 05-15-2021, 03:44 PM
balavaka balavaka is offline character style Windows 10 character style Office 2013
Novice
character style
 
Join Date: May 2021
Posts: 25
balavaka is on a distinguished road
Default Kindly look

In the below url and attached Screenshot.

Private Use Area (U+E000 - U+F8FF) - Test for Unicode support in Web browsers
Attached Images
File Type: png Capture.PNG (24.2 KB, 22 views)
Reply With Quote
  #14  
Old 05-15-2021, 11:25 PM
macropod's Avatar
macropod macropod is offline character style Windows 10 character style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #15  
Old 05-16-2021, 12:28 AM
Guessed's Avatar
Guessed Guessed is online now character style Windows 10 character style Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply



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
character style 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft