PDA

View Full Version : fonts in range should be in Normal6 style



saban
11-12-2007, 07:15 AM
Dim rng2 As Range
Set rng2 = ActiveDocument.Range.Duplicate
With rng2.Find.Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
rng2.TextRetrievalMode.IncludeHiddenText = False
End With
Do While rng2.Find.Execute
With rng2.Style
.Name = "Normal6"
End With
With rng2.Font
.Reset
.Bold = False
.italic = False
.Underline = False
End With

If rng2.End = ActiveDocument.Range.End Then Exit Do
rng2.Collapse wdCollapseEnd
If rng2.Characters(1) = Chr(13) & Chr(7) Then rng2.Move wdCharacter, 1
Loop

Does anyone have any idea how can I set the style of selected fonts to Normal6

OTWarrior
11-12-2007, 07:37 AM
Selection.Style = ActiveDocument.Styles("Normal 6")

TonyJollans
11-12-2007, 07:57 AM
Why not put it in the F&R?

With rng2.Find.Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
rng2.TextRetrievalMode.IncludeHiddenText = False
End With
rng2.Find.Replacement.Style = ActiveDocument.Styles("Normal6")
rng2.Find.Execute eplace:=wdreplaceall

saban
11-12-2007, 08:13 AM
wow thnx for a quick reply

One more question would it be possible to also get other atributes from fonts like if they are centered, line spacing and so on

and aply those atributes to Normal6 style

fumei
11-12-2007, 08:26 AM
Yes, of course.

And if you are going to use With, you may as well USE With....
With rng2.Find
With .Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
End With
rng2.TextRetrievalMode.IncludeHiddenText = False

.Replacement.Style = ActiveDocument.Styles("Normal6")
.Execute Replace:=wdReplaceAll
End With

One other comment. What the heck is a style named "Normal6"? Very informative.

saban
11-12-2007, 08:53 AM
Ah nevermind that normal6 I changed this style to normal

But this is so wierd why does it loop all the time

Dim rng2 As Range
Set rng2 = ActiveDocument.Range.Duplicate
With rng2.Find.Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
rng2.TextRetrievalMode.IncludeHiddenText = False
End With
Do While rng2.Find.Execute
rng2.Find.Replacement.Style = ActiveDocument.Styles("Normal")
rng2.Find.Execute Replace:=wdReplaceAll
With rng2.Font
.Reset
.Bold = False
.italic = False
.Underline = False
End With

If rng2.End = ActiveDocument.Range.End Then Exit Do
rng2.Collapse wdCollapseEnd
Selection.Collapse direction:=wdCollapseEnd
If rng2.Characters(1) = Chr(13) & Chr(7) Then rng2.Move wdCharacter, 1

even on a normal text without tables
Any ideas

OTWarrior
11-12-2007, 08:58 AM
my guess is this line:

Do While rng2.Find.Execute

should be something like

Do While rng2.Find.Execute = true

I have never used "Do While" before, so this is a wild guess

saban
11-12-2007, 08:58 AM
I think i know what the problem is, but I dont know how to fix it

In the text there should be no Bold text at all and then this code exits loop if there is even one word bolded it will go into loop

strange

saban
11-12-2007, 09:00 AM
Do While rng2.Find.Execute = True


Tried it still the same,

I dont get this at all?????

OTWarrior
11-12-2007, 09:01 AM
put in at the top
on error goto error1

and below your code:

exit sub

error1:
msgbox err.description

NB: If there shouldn't be any bold text couldn't you make all the text in the document not bold before your code runs?

saban
11-12-2007, 09:16 AM
No no I didnt say there should be no bold text it loops when bold text is in Document

will try that error thing

Edited:
Tried that error thing but all I get is empty message box and it is looping also i have to use ctrl+pause to exit the code

OTWarrior
11-12-2007, 09:33 AM
In the text there should be no Bold text at all and then this code exits loop if there is
even one word bolded it will go into loop

I read this as you saying there should be no bold text, sorry about that.

I saw this in the help:

Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop


so I think it should be like:



Dim rng2 As Range
Set rng2 = ActiveDocument.Range.Duplicate
With rng2.Find.Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
rng2.TextRetrievalMode.IncludeHiddenText = False
End With

Do While rng2.Find.Execute
rng2.Find.Replacement.Style = ActiveDocument.Styles("Normal")
rng2.Find.Execute Replace:=wdReplaceAll
With rng2.Font
.Reset
.Bold = False
.italic = False
.Underline = False
End With
Loop

If rng2.End = ActiveDocument.Range.End Then Exit Do
rng2.Collapse wdCollapseEnd
Selection.Collapse direction:=wdCollapseEnd

If rng2.Characters(1) = Chr(13) & Chr(7) Then rng2.Move wdCharacter, 1

is that better?

TonyJollans
11-12-2007, 09:58 AM
Ah nevermind that normal6 I changed this style to normal

But this is so wierd why does it loop all the time

Dim rng2 As Range
Set rng2 = ActiveDocument.Range.Duplicate
With rng2.Find.Font
.Bold = False
.italic = False
.Hidden = False
.Underline = False
.Name = "Times New Roman"
.Size = 12
rng2.TextRetrievalMode.IncludeHiddenText = False
End With
Do While rng2.Find.Execute
rng2.Find.Replacement.Style = ActiveDocument.Styles("Normal")
rng2.Find.Execute Replace:=wdReplaceAll
With rng2.Font
.Reset
.Bold = False
.italic = False
.Underline = False
End With

If rng2.End = ActiveDocument.Range.End Then Exit Do
rng2.Collapse wdCollapseEnd
Selection.Collapse direction:=wdCollapseEnd
If rng2.Characters(1) = Chr(13) & Chr(7) Then rng2.Move wdCharacter, 1

even on a normal text without tables
Any ideas

Saban,

You seem to keep on doing variations on the same thing and getting in a tangle. Try not to throw code together quite so quickly - a little more effort up front will pay dividends. Work out what you actually want and then try to code to get it.

I have no idea why your code loops - I don't have enough information to go on, but it seems unlikely that this code is ever going to be right ...

Do While rng2.Find.Execute
' ...
rng2.Find.Execute Replace:=wdReplaceAll
' whatever

fumei
11-12-2007, 10:08 AM
I have asked previously, but...why are you using .Duplicate?

Also, I do not understand what it is, exactly, you are trying to do.

Are you looking for words? If so, then you could use Words.Sub What()
Dim aWord
Dim r As Range
Set r = ActiveDocument.Range
For Each aWord In r.Words
If IsWhatever(aWord) = True Then
aWord.Style = "Normal"
End If
Next
End Sub

Function IsWhatever(ByRef aWord As Variant) As Boolean
If aWord.Font.Bold = False And _
aWord.Font.Italic = False And _
aWord.Font.Hidden = False And _
aWord.Font.Underline = False And _
aWord.Font.Name = "Times New Roman" And _
aWord.Font.Size = 12 Then
IsWhatever = True
End If
End FunctionThe function checks the attributes. Each word goes through the function, if the word has those attributes, it makes the word Normal - a poor idea, but whatever.

If you are checking paragraphs, then use a paragraph object.Sub UsingParas()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If IsWhatever2(oPara) = True Then
oPara.Style = "Normal"
End If
Next
End Sub

Function IsWhatever2(oPara As Paragraph) As Boolean
If oPara.Range.Font.Bold = False And _
oPara.Range.Font.Italic = False And _
oPara.Range.Font.Hidden = False And _
oPara.Range.Font.Underline = False And _
oPara.Range.Font.Name = "Times New Roman" And _
oPara.Range.Font.Size = 12 Then
IsWhatever2 = True
End If
End Function

fumei
11-12-2007, 10:36 AM
RE: Tony's comment...nope, it won't.

I totally agree. It would be far far better to actually work out, precisely, what it is you want to happen. I know I am a nag, and "rip" into people on this.

However, I kid you not. Very few people do this, but it is a good idea.

Write out what it is you want to have happen. Not code it. Write it out. Gasp! On paper.

OK, OK, you can do it electronically.

But I have found that often it is actually better doing it on paper.

You can circle stuff you determine is in the wrong place and arrow it up to the right place.

Work it out step-by-step. That is the way VBA deals with it, so it is a VERY good idea to start thinking that way. Step-by-step.

Coding is, IMO, the least important part of.....ummm, coding. I mean by that, the writing of code.

Far more important is the logic behind what you are trying to do. And that, my friends, means thinking about what you are trying to do.

Getting the code (to do the logic you have figured out) is much much easier when you know EXACTLY what it is, logically, you are trying to do.

It makes it easier to ask questions, as you can ask specifically: I want to do THIS, how do I do that?

ALL code, without exception, uses logic. Until we have computers that can read minds and extrapolate that into logic, we have to GIVE the computer the logic. It can not, yet, take desires and translate that into logic.

Even if they could take desires and translate it into logic, bottom line though is it still needs logic.

That is where we should start. NOT by just coding. Oh, once we get advanced - say a Tony Jollans - we can jump and and just write code.

However, he can only do that because he has worked with it long enough that he understands the logic behind it.

Oh sure, we experiment, we try stuff (coding) and see what happens. The point of doing that, though, is to build up chunks of logic in our minds.

When those chunks are tested and found consistently viable, then we add them to our library. That library is both within our minds, our concepts, our knowledge, but also (hopefully) in a real file.

saban
11-12-2007, 11:35 AM
Thnx guy for those replies I sure will look into them carefully


Just to see what I am actually strugling with
The problem that I am facing is:

In documents I work on are full of different styles (but fonts are just bolditalic, italic, bold and normal)

Those styles cause trouble with certain translation program

So I thought if I select all fonts that are bolditalic (or italic...) and asign them a common style (Normal) but afterwards format them back to bolditalic, centered or whatever they were formatted before asigning normal style to them.

So the fonts will look the same after this proces as they were before.
It is just that instead of style ex. customMystyle now it will be Normal style

That is prety much all the problem I have

Thnx again
Saban

TonyJollans
11-12-2007, 11:39 AM
Gerry,

The duplicate is my fault - just being over-cautious.

TonyJollans
11-12-2007, 12:10 PM
To take this a bit further ..

What is the difference between
Set R = ActiveDocument.Range
and
Set R = ActiveDocument.Range.Duplicate

saban
11-12-2007, 12:47 PM
Duplicate statement gives back another range ??
It finds some range and them imediatelly looks for another instance of it
Or what ?

saban
11-12-2007, 01:58 PM
fumei why does this part not change style to normal
aWord.Style = "Normal"

This code of yours is what I want and it gives the same results as my code(most of it written by Tony:)) - but my goes into a loop and your seems it dont

will test it further and let you know

saban
11-13-2007, 02:48 AM
I dont have any idea how should I solve this problem

I need to change style "TypDedocument" into "Normal" but all formatting of the text should stay the same (bolitalic=bolditalic, centered = centered...)

I am realy running out of ideas here and I cant figure it out

Any help maybe
Saban

fumei
11-13-2007, 01:29 PM
For starters, use styles properly.

And again, try and explain what you are trying to do.

If the format is exactly the same...WHY are you doing this?

It does not make any sense to me.

This chunk of text has X style:

1. is that really its style? Or is it also manually formatted?

2. I want to change it to "Normal".....but also make Normal exactly the same format as it....already IS.

This does not make any sense to me.

But then, I have thousands of documents, and not a single one uses "Normal". So I simply do not get it. Sorry.

If TypDocument is a real style, then you can search for instances of it. By real style I mean, there are NO manual format changes to it.

If it is a real style (and no manual changes), then it is straightforward to find it, and make that text a different style.

If you have ANY manual changes, then you must test for them. Every one.

fumei
11-13-2007, 01:32 PM
"So I thought if I select all fonts that are bolditalic (or italic...) and asign them a common style (Normal) but afterwards format them back to bolditalic, centered or whatever they were formatted before asigning normal style to them.

So the fonts will look the same after this proces as they were before.
It is just that instead of style ex. customMystyle now it will be Normal style"


Plain and simple....this is BAD use of Word. It is not how Word is designed to be used. It goes against the whole design use of styles.

saban
11-13-2007, 02:48 PM
the problem is with trados which is a program for translation.

If text is in some custom style and is also additional formatted (ex. if I have custom style which is bold by default and then someone unbolds it and this is where it gets to a problem (it is an improper style use) anyways when that kind of text is to be translated trados automaticly set this text to bold because this custom style is bold in base.

that is why only this would help, cause I cant get people to use styles properly

Do you have any ideas how could I do that

and yes this is the point that the text looks the same for the eye after this process only style is now normal instead of custom

saban
11-14-2007, 02:47 AM
So the fonts will look the same after this proces as they were before.
It is just that instead of style ex. customMystyle now it will be Normal style



This is exactly what I need fumei, I know it is a bad use of word but this is the only thing that would help until trados release some patch that it will be able to deal with those kind of additional formatting of styles

And it also seems very unlogical to me but I guess trados will accept aditional formating only from Normal style, and not from other styles (ex. Normal style can be bolded underlined, italic .... and trados will preserve that kind of formatting but if some custom style is additionaly bolded, underlined ... it will not preserve formatting but set it back to base formatting of that style

fumei
11-14-2007, 01:12 PM
You simply do not understand.

text A: 12 pts, bold

textB: 12 pts, italics

textC: 12 pts underline

You tell me, how you can make all three of those be "Normal" at the same time? That is what you are saying.

Get the individual formatting (bold, italic, underline), make it "Normal"....and then change "Normal" for textA.....change it AGAIN for textB...change it AGAIN for textC.

Sorry, I can not help you with this.

saban
11-15-2007, 06:20 AM
No but not at the same time one set of formatting at the time

1.Change all bold characters to normal style and put them back to bold
2.Change all italic characters to normal and put them back to italic

That is what I thought

fumei
11-15-2007, 08:01 AM
1.Change all bold characters to normal style and put them back to bold
2.Change all italic characters to normal and put them back to italic

This create two different Normal. Well, one Normal, that is changed. What you end up is that horrid Normal + yadda yadda attributes.

This is far worse than "TypDocument".

Worst of all, it is pointless IMO. I still have no idea WHY this needs to be done.

OTWarrior
11-15-2007, 10:08 AM
So this translation software will only work on "Normal" characters, and you want to change the contents of the document so it is set as normal, runs the translation, then sets it back to bold/italic?

Does it make that much difference what the formatting is once it is translated other than looking nice?

If this program is giving you these issues, then are you not able to use other translation software?

saban
11-15-2007, 01:08 PM
Formatting matters very much in translation, and I dont have a slightest idea why would translation program except just normal style.

(ex. If style is custom and lets say it is not bold and not italic and then someone bolds or italics this text - the trados will translate it and set formatting to what this custom style was before this man bolded it)

It is hard to explain if you did not see it for yourself maybe I could attach some example of this problem

I know fumei it is pretty unlogical ending up with bunch of Normal styles that are additional formated (but for now this is the only way - until Trados release a patch for this problem)

But this is exactly what I want, to have many derivates of normal style :

Normal
Normal+Bold
Normal+Bold+Italic
Normal+Bold+Italic+Underline
etc..

fumei
11-16-2007, 07:51 AM
Sorry, but I will not help to do that. Actually, I should amend that...the help to do that is already here.

Good luck.

OTWarrior
11-16-2007, 09:04 AM
I don't know much about foreign languages, but why does having the words in bold or italics affect the translation?

saban
11-17-2007, 08:41 AM
It is complicated but those documents are specific and bold text means that it was added to original documents (one document is composed of various diferent documents and the bold text is the one which is new)

Anyways the bolded text must remain

saban
11-17-2007, 08:47 AM
If I need to center the text I need to check for paragraphs right?

ex . I look for bolded words and set them to normal and bold them back, then if this paragraph where word was found was centered before I set normal style to it, I need to center this paragraph back - this is the part that is bothering me