
Tenho um documento do Microsoft Word com duas seções de texto. O primeiro é em forma de parágrafo, o segundo é aquele em forma de parágrafo dividido em segmentos e colocado em uma tabela sem pontuação. Existe uma função que eu possa usar para que:
- Se: No texto pontuado, uma seção é seguida por um sinal de pontuação,
- Então: No texto sem pontuação da tabela, a pontuação é adicionada.
Se isso não for possível no Microsoft Word, existem outras ferramentas sugeridas para atingir esse objetivo?
Aqui está uma captura de tela tirada no Microsoft Word para ilustrar meu problema.
Responder1
Você pode adicionar pontuação ausente aos parágrafos nas células das tabelas com o código a seguir. Quanto às condições em que isso seria executado, você deverá dar uma olhada no meu comentário e fornecer mais informações.
Sub AddPunction()
Dim para As Paragraph, tbl As Table, tRow As Row
Dim tCell As Cell, cRng As Range, pRng As Range
For Each tbl In ActiveDocument.Tables
For Each tRow In tbl.rows
For Each tCell In tRow.Cells
Set cRng = tCell.Range
cRng.MoveEnd wdCharacter, -1
If cRng.Paragraphs.Count > 0 Then
For Each para In cRng.Paragraphs
Set pRng = para.Range
If Asc(pRng.Characters.Last) = 13 Then
pRng.MoveEnd wdCharacter, -1
End If
If Not Asc(pRng.Characters.Last) = 46 Then
pRng.Text = pRng.Text & "."
End If
Next para
End If
Next tCell
Next tRow
Next tbl
End Sub
Com base nas suas perguntas adicionais colocadas como comentários, aqui estão os suplementos à minha resposta original:
Para obter recursos sobre como criar ou executar uma macro, use este link de suporte da Microsoft. https://support.office.com/en-us/article/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c
Quanto à sua outra questão de adaptar o código acima com base nas novas informações fornecidas, veja como modificá-lo.
Sub TableLookBackAddPunctuation()
Dim para As Paragraph, tbl As Table, tRow As Row
Dim tCell As Cell, cRng As Range, pRng As Range
Dim rng As word.Range
For Each tbl In ActiveDocument.Tables
For Each tRow In tbl.rows
Set cRng = tRow.Cells(1).Range
cRng.MoveEnd wdCharacter, -1
If cRng.Paragraphs.Count > 0 Then
For Each para In cRng.Paragraphs
Set pRng = para.Range
If Asc(pRng.Characters.Last) = 13 Then
pRng.MoveEnd wdCharacter, -1
End If
Select Case Asc(pRng.Characters.Last)
Case 33, 34, 35, 36, 37, 38, 39, 40, _
41, 42, 43, 44, 45, 46, 63
'do nothing, punctuation already set
Case Else
Set rng = pRng
rng.Collapse wdCollapseStart
With rng.Find
.ClearFormatting
.Format = False
.Forward = False
.MatchCase = True
.Text = pRng.Text
.Wrap = wdFindStop
.Execute
If .found Then
rng.MoveEnd wdCharacter, 1
Select Case Asc(rng.Characters.Last)
Case 33, 34, 35, 36, 37, 38, 39, 40, _
41, 42, 43, 44, 45, 46, 63
pRng.Text = pRng.Text & rng.Characters.Last
Case Else
'do nothing, there's no punctuation
End Select
End If
End With
End Select
Next para
End If
Next tRow
Next tbl
End Sub