无法让 WholeStory 使用 Excel VBA 选择和格式化 Word 文档中的所有文本



我需要能够生成一个报告(在Word中(,该报告利用存储在Excel中的一堆数据。当我尝试格式化整个Word文档(报告标题和我从Excel复制的所有内容(时,我遇到了问题,以便所有内容都是单倍行距的,并且在之前或之后没有段落间距。"整个故事"命令/选择不起作用。提前感谢您的帮助!!

Sub Generate_Report()
Dim appWD As Word.Application 
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.Documents.Add
<<Sub where I move/arrange data from a bunch of sheets to Sheets("Template")>>
Sheets("Template").UsedRange.Copy
With appWD.Selection
.Font.Size = 14
.Font.Name = "Calibri Light (Headings)"
.Font.Bold = True
.Font.Underline = wdUnderlineSingle
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeText ("NAME OF REPORT TITLE") & vbNewLine & vbNewLine
.Paste
End With
With appWD.WholeStory.ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
End With
Sheets("Template").Cells.ClearContents
End Sub

在第一个结尾之后尝试

appWD.Selection.WholeStory
With appWD.Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceDouble
End With

'Sheets("Template"(之间你需要的一切。UsedRange.Copy"和"Sheets("Template"(。Cells.ClearContent' 是:

With appWD.ActiveDocument.Range
.Font.Size = 14
.Font.Name = "Calibri Light (Headings)"
.Font.Bold = True
.Font.Underline = wdUnderlineSingle
.TypeText ("NAME OF REPORT TITLE") & vbNewLine & vbNewLine
.Characters.Last.Paste
With .ParagraphFormat
.Alignment = wdAlignParagraphCenter
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacingRule = wdLineSpaceSingle
End With
End With

最新更新