
두 개의 텍스트 섹션이 포함된 Microsoft Word 문서가 있습니다. 첫 번째는 단락 형식이고, 두 번째는 단락 형식을 세그먼트로 나누어 구두점 없이 표에 배치하는 것입니다. 다음과 같이 사용할 수 있는 기능이 있습니까?
- 만약에: 구두점 본문에서는 섹션 뒤에 구두점을 붙입니다.
- 그 다음에: 표 내 구두점이 없는 텍스트에는 구두점이 추가됩니다.
Microsoft Word에서 이것이 가능하지 않은 경우 이 목표를 달성하기 위해 제안된 다른 도구가 있습니까?
다음은 내 문제를 설명하기 위해 Microsoft Word에서 찍은 스크린샷입니다.
답변1
다음 코드를 사용하면 표 셀의 단락에 누락된 구두점을 추가할 수 있습니다. 이것이 실행되는 조건에 대해서는 내 의견을 살펴보고 더 많은 정보를 제공해야 합니다.
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
의견으로 제출된 추가 질문을 바탕으로 원래 답변에 대한 보충 내용은 다음과 같습니다.
매크로 생성 또는 실행에 대한 리소스를 보려면 이 Microsoft 지원 링크를 사용하세요. https://support.office.com/en-us/article/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c
새로 제공된 정보를 기반으로 위 코드를 조정하는 다른 질문에 대해서는 이를 수정하는 방법입니다.
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