Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2020, 07:44 AM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 08-26-2020, 03:55 PM
Guessed's Avatar
Guessed Guessed is offline VBA to conditionally hide text by language/structure? Windows 10 VBA to conditionally hide text by language/structure? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

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
Reply With Quote
  #3  
Old 08-26-2020, 11:40 PM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 08-26-2020, 11:53 PM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

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?
Reply With Quote
  #5  
Old 08-27-2020, 12:12 AM
Guessed's Avatar
Guessed Guessed is offline VBA to conditionally hide text by language/structure? Windows 10 VBA to conditionally hide text by language/structure? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

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
Reply With Quote
  #6  
Old 08-27-2020, 12:57 AM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

Here's a sample of the file.

The thing with ALT dragging and selecting doesn't work.
Attached Files
File Type: docx testX.docx (15.3 KB, 8 views)
Reply With Quote
  #7  
Old 08-27-2020, 01:46 AM
Guessed's Avatar
Guessed Guessed is offline VBA to conditionally hide text by language/structure? Windows 10 VBA to conditionally hide text by language/structure? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

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
If you wanted to work with styles with languages assigned (and you should) you can change
aRng.LanguageID = wdEnglishAUS
to
aRng.Style= "Normal"
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 08-27-2020, 03:02 AM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 08-27-2020, 03:20 AM
Guessed's Avatar
Guessed Guessed is offline VBA to conditionally hide text by language/structure? Windows 10 VBA to conditionally hide text by language/structure? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

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
Reply With Quote
  #10  
Old 08-31-2020, 06:50 AM
Charles Kenyon Charles Kenyon is offline VBA to conditionally hide text by language/structure? Windows 10 VBA to conditionally hide text by language/structure? Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

To have paragraphs side-by-side, you could also use a two-column table with one row for each paragraph.
Reply With Quote
  #11  
Old 08-31-2020, 11:14 PM
tyxanu tyxanu is offline VBA to conditionally hide text by language/structure? Windows 8 VBA to conditionally hide text by language/structure? Office 2013
Novice
VBA to conditionally hide text by language/structure?
 
Join Date: Aug 2020
Posts: 13
tyxanu is on a distinguished road
Default

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

Thread Tools
Display Modes


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
VBA to conditionally hide text by language/structure? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:33 AM.


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