Create a Word macro Autor vlákna: Jean-Christophe Duc
|
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 Velká Británie Local time: 14:01 Člen (2014) japonština -> angličtina 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 | | |
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] | | | Stepan Konev Ruská federace Local time: 17:01 angličtina -> ruština 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 Ruská federace Local time: 17:01 angličtina -> ruština 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 | | | | Philippe Locquet Portugalsko Local time: 14:01 Člen (2013) angličtina -> francouzština + ...
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. | | |
I was also wondering how to make positive use of ChatGPT,
this could be a good starting point | | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Create a Word macro CafeTran Espresso | You've never met a CAT tool this clever!
Translate faster & easier, using a sophisticated CAT tool built by a translator / developer.
Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools.
Download and start using CafeTran Espresso -- for free
Buy now! » |
| Wordfast Pro | Translation Memory Software for Any Platform
Exclusive discount for ProZ.com users!
Save over 13% when purchasing Wordfast Pro through ProZ.com. Wordfast is the world's #1 provider of platform-independent Translation Memory software. Consistently ranked the most user-friendly and highest value
Buy now! » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |