#1
|
|||
|
|||
VBA to conditionally hide text by language/structure?
Is anyone willing to help with some VBA code for this situation I am facing with daily?
I have many Word documents with several hundred pages of bilingual text(and multilingual sometimes) structured like below and I have to: -hide one language(or more) every time maximum one or two paragraphs at once(vertically) , even smaller and smaller sentences at once, because not every file I get is nicely divided. So it's a very tedious job, horrible. The proofing is never correct(from the client) so I can't use find(language)&replace(with hidden) Or, a solution for highlighting one language(column) would be also awesome as I can afterwards hide what is not highlighted? Would be grateful!Thanks! xz — ImgBB |
#2
|
||||
|
||||
Are you saying the macro can't use styles or language settings to identify the language that is used? If so, how do you propose the macro identifies the chosen language?
I think we would need to see a sample document to understand what needs to be done.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Just take a look here: xz — ImgBB
Styles are the same on both columns. In 90% of the cases even the proofing for both columns is set similar(let's say ENGLISH(US) for both, although we technically have english on the left and german on the right). I have to manually go all the way down selecting one or more paragraphs at a time(depending on how the file is structured) and hide one language(ALT+Z, my personal macro for fast hiding), repeatedly, thousands of times |
#4
|
|||
|
|||
So in this case:
-do I have at least a solution to automatically repair the proofing so I can afterwards use find&replace or a macro? |
#5
|
||||
|
||||
I can't see your screenshot because I am behind corporate firewall that blocks that site.
Have you considered vertical selections? This is done by holding the Alt key before clicking and dragging. This will allow you to then apply a character style to the selection and that character style could have a different language attached to it. If that doesn't work then I will need to see what you are looking at.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
Here's a sample of the file.
The thing with ALT dragging and selecting doesn't work. |
#7
|
||||
|
||||
OK, I see your sample has lots of section breaks and it appears that consistently your right column is content in a section that follows a column break. This pattern could break in a real document if a section continues to a new page but based on your sample, this code works to assign a different language to anything following a column break.
Code:
Sub SetLanguages() Dim aSect As Section, aRng As Range, lngPos As Long ActiveDocument.Range.LanguageID = wdGerman 'language for first column For Each aSect In ActiveDocument.Sections Set aRng = aSect.Range lngPos = InStr(aRng.Text, Chr(14)) If lngPos > 0 Then aRng.MoveStart Unit:=wdCharacter, Count:=lngPos aRng.LanguageID = wdEnglishAUS 'language for second column End If Next aSect End Sub aRng.LanguageID = wdEnglishAUS to aRng.Style= "Normal"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
This is great, indeed! Thanks a lot!
I can now set the proofing for the majority of the paragraphs(those without section breaks) and use a quick find&replace to highlight&hide. For the rest of the parts(where proofing1 overlapped proofing2), will have to do some repair and a manual hide/unhide. |
#9
|
||||
|
||||
If you have control over the format, I would HIGHLY recommend converting to a two column table layout instead. Having two side by side table columns allows you far more control of where the content sits and it also makes it simple to split the document into separate versions. When you are dealing with the complexities of multiple languages you should embrace every possible chance to structure the content so it is organised.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#10
|
|||
|
|||
To have paragraphs side-by-side, you could also use a two-column table with one row for each paragraph.
|
#11
|
|||
|
|||
No, I almost never have control over the format.
The clients send them that way and I can't do anything about that but to accept or reject the job |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to text heading1 text heading1 text? How to collapse or hide text in the middle of a line. | TImer | Word | 7 | 08-10-2020 12:52 AM |
Conditionally Color Formatting Text selected from a dropdown list in Word 2010 | pgammag | Word | 9 | 08-20-2019 04:17 PM |
Conditionally hide parts of a document | elaineAda | Word VBA | 0 | 04-01-2019 10:00 PM |
Insert a text conditionally | deboer | Word | 1 | 05-04-2014 03:35 PM |
Header must toggle text & color + show count of conditionally formatted cells below | Franktoon | Excel | 3 | 02-18-2014 02:10 PM |