テキストをフォーマットするマクロを作成しようとしています。
元のデータは次のようになります。
This is sentence one of paragraph one. This is
sentence two of paragraph one. This is
sentence three of paragraph one. This is sentence
four of paragraph one. This is sentence five of
paragraph one.
This is sentence one of paragraph two. This is
sentence two of paragraph two. This is
sentence three of paragraph two. This is sentence
four of paragraph two. This is sentence five of
paragraph two.
これは、テキストを次のように表示したいものです。
This is sentence one of paragraph one. This is sentence two of paragraph one. This is
sentence three of paragraph one. This is sentence four of paragraph one. This is
sentence five of paragraph one.
This is sentence one of paragraph two. This is sentence two of paragraph two. This is
sentence three of paragraph two. This is sentence four of paragraph two. This is
sentence five of paragraph two.
このマクロは、テキストがページ全体を埋め、すべての単語の間にスペースが 1 つだけあることを確認します。段落構造を保持する必要があります。
このマクロを Excel から呼び出して、Word から読みやすさの統計を実行しています。
これが私がこれまでに持っているコードです:
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub Test_Button1()
Dim file As String
Dim StatText As String
Dim rs As Variant
Dim row_count As Integer
Dim header_count As Integer
row_count = 0
header_count = 0
Sheets("Sheet1").Select
Range("B5").Select
Set appWD = New Word.Application
appWD.Visible = True
Do Until IsEmpty(ActiveCell)
row_count = row_count + 1
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
ActiveCell.Copy
appWD.Documents.Add
appWD.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
appWD.ActiveDocument.Select
With appWD.Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
End With
If row_count = 1 Then
ActiveCell.Offset(-1, 0).Select
For Each rs In appWD.ActiveDocument.readabilitystatistics
header_count = header_count + 1
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = rs.Name
Next rs
ActiveCell.Offset(1, -header_count).Select
End If
For Each rs In appWD.ActiveDocument.readabilitystatistics
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = rs.Value
StatText = StatText & rs.Name & " - " & rs.Value & vbCr
Next rs
appWD.ActiveDocument.Select
appWD.Selection.Delete
appWD.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
ActiveCell.Offset(1, -header_count).Select
Loop
appWD.Quit SaveChanges:=wdDoNotSaveChanges
Set appWD = Nothing
End Sub