Create a Word macro
Thread poster: Jean-Christophe Duc
Jean-Christophe Duc
Jean-Christophe Duc  Identity Verified
France
Local time: 12:21
English to French
+ ...
Aug 28, 2024

Hi
I am trying to create a macro to create a bilingual file for translation in Studio.

The file I get has a series of tables, 2 columns each, one with the text to translate, the other empty for the translation.

I am trying to copy the text from column 1 into column 2, then to go back to column 1 and set it to Hidden text.
This operation creates a 3rd column, which I need to delete.

I thought I could record a simple macro, but you cannot record m
... See more
Hi
I am trying to create a macro to create a bilingual file for translation in Studio.

The file I get has a series of tables, 2 columns each, one with the text to translate, the other empty for the translation.

I am trying to copy the text from column 1 into column 2, then to go back to column 1 and set it to Hidden text.
This operation creates a 3rd column, which I need to delete.

I thought I could record a simple macro, but you cannot record mouse operations, and I don't know VBA well enough to create this operation.
Collapse


 
Dan Lucas
Dan Lucas  Identity Verified
United Kingdom
Local time: 11:21
Member (2014)
Japanese to English
Here's one approach Aug 28, 2024

Maybe something like this?
You need to be careful with this because it goes through all tables in the document, so they all need to have the same layout.
Indenting didn't come out very well...
Very minimal testing, but does work for a simple document with one table.

Sub CopyAndHideTextInAllTables()

Dim tbl As Table
Dim cell As Cell
Dim rowIndex As Long
Dim tblIndex As Long

Application.ScreenUpdating =
... See more
Maybe something like this?
You need to be careful with this because it goes through all tables in the document, so they all need to have the same layout.
Indenting didn't come out very well...
Very minimal testing, but does work for a simple document with one table.

Sub CopyAndHideTextInAllTables()

Dim tbl As Table
Dim cell As Cell
Dim rowIndex As Long
Dim tblIndex As Long

Application.ScreenUpdating = False

' Loop through each table in the document
For tblIndex = 1 To ActiveDocument.Tables.Count
Set tbl = ActiveDocument.Tables(tblIndex)

' Loop through each row in the current table
For rowIndex = 1 To tbl.Rows.Count
' Copy text from Column 1 to Column 2
tbl.Cell(rowIndex, 2).Range.Text = tbl.Cell(rowIndex, 1).Range.Text

' Set text in Column 1 to hidden
With tbl.Cell(rowIndex, 1).Range.Font
.Hidden = True
End With
Next rowIndex

' Remove the third column if it exists
If tbl.Columns.Count > 2 Then
tbl.Columns(3).Delete
End If
Next tblIndex

Application.ScreenUpdating = True

MsgBox "Operation completed successfully for all tables!", vbInformation

End Sub
Collapse


 
Jean-Christophe Duc
Jean-Christophe Duc  Identity Verified
France
Local time: 12:21
English to French
+ ...
TOPIC STARTER
Thanks Aug 28, 2024

however I am told
If tbl.Columns.Count 2 Then
is not correct

However the rest of the macro works perfectly.
Many thanks

[Edited at 2024-08-28 17:35 GMT]


Dan Lucas
 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 14:21
English to Russian
Try this VBA macro (Alt+F11, Insert Module ... F5) Aug 28, 2024

I assume that you have multiple tables in a file scattered in between other regular text paragraphs:
Blah-blah-blah.
[Table1]
Blah-blah-blah. Blah-blah-blah.
[Table2]
Blah-blah-blah-blah-blah.
[Table3]

etc...
If this is not your case, please let me know.
======
Sub DuplicateTables()
'
' DuplicateTables Macro
'
'
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
Se
... See more
I assume that you have multiple tables in a file scattered in between other regular text paragraphs:
Blah-blah-blah.
[Table1]
Blah-blah-blah. Blah-blah-blah.
[Table2]
Blah-blah-blah-blah-blah.
[Table3]

etc...
If this is not your case, please let me know.
======
Sub DuplicateTables()
'
' DuplicateTables Macro
'
'
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.EndKey Unit:=wdColumn, Extend:=True
Selection.Copy
Selection.Paste
Selection.Font.Hidden = wdToggle
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
======
*Press F5 [while in the VBA module window] as many times as you need to reach the end of your document. Probably you can make it run multiple times until it has reached the end of document, but I don't know how.

[Edited at 2024-08-29 00:26 GMT]
Collapse


 
Stepan Konev
Stepan Konev  Identity Verified
Russian Federation
Local time: 14:21
English to Russian
Just in case it may help you in your further research... Aug 29, 2024

I created that macro by recording my clicks and key strokes.
Start recording a macro then click and press as follows:

1. Press F5
2. Select 'Table'
3. Click 'Next'
4. Click 'Close'
5. Press Alt+Shift+PageDown
6. Press Ctrl+C
7. Press Ctrl+V
8. Press Ctrl+Shift+H
9. Press Arrow Down

Stop recording.
Now you get a macro that you can run in VBA mode by pressing F5 multiple times as I described above in my previous
... See more
I created that macro by recording my clicks and key strokes.
Start recording a macro then click and press as follows:

1. Press F5
2. Select 'Table'
3. Click 'Next'
4. Click 'Close'
5. Press Alt+Shift+PageDown
6. Press Ctrl+C
7. Press Ctrl+V
8. Press Ctrl+Shift+H
9. Press Arrow Down

Stop recording.
Now you get a macro that you can run in VBA mode by pressing F5 multiple times as I described above in my previous comment.

[Edited at 2024-08-29 00:56 GMT]
Collapse


Dan Lucas
 
Jean-Christophe Duc
Jean-Christophe Duc  Identity Verified
France
Local time: 12:21
English to French
+ ...
TOPIC STARTER
@Stepan Aug 29, 2024

Thanks for the tip

 
Philippe Locquet
Philippe Locquet  Identity Verified
Portugal
Local time: 11:21
Member (2013)
English to French
+ ...
maybe? Aug 30, 2024

Hi,

Not sure if this will help but, I've had success in the past working on VBA using Copilot or Chat GPT. Adjusting the prompts and iteration was needed but, I got there in the end. This can be useful if you're not familiar with that kind of code and if you are willing to spend time on it.


 
Jean-Christophe Duc
Jean-Christophe Duc  Identity Verified
France
Local time: 12:21
English to French
+ ...
TOPIC STARTER
Thanks Aug 30, 2024

I was also wondering how to make positive use of ChatGPT,
this could be a good starting point


Philippe Locquet
 


To report site rules violations or get help, contact a site moderator:

Moderator(s) of this forum
Laureana Pavon[Call to this topic]

You can also contact site staff by submitting a support request »

Create a Word macro






Anycount & Translation Office 3000
Translation Office 3000

Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.

More info »
Pastey
Your smart companion app

Pastey is an innovative desktop application that bridges the gap between human expertise and artificial intelligence. With intuitive keyboard shortcuts, Pastey transforms your source text into AI-powered draft translations.

Find out more »