从Excel VBA写入Word文档 [英] Write to Word Document from Excel VBA
本文介绍了从Excel VBA写入Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够从VBA宏中写入Word文档,但是我在语法上遇到麻烦,无法生成标题,段落,表等...
I am able to write to Word Document from a VBA macro, but I am having trouble with syntax to generate headers, paragraphs, tables etc...
此示例将两行写入Word文档,但都以标头样式显示.我想要一行标题和段落或常规"样式的一行...
This example writes two lines to a Word Document, but both come out as header style. I would like one line header and one line in paragraph or "normal" style...
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
.Style = "Heading 1"
.TypeText ("My Heading")
.TypeParagraph
.Style = "Normal"
.TypeText ("Some regular paragraph text")
End With
推荐答案
这就是我想要的.
With .Selection
.Style = "Heading 1"
.TypeText "Header 1"
.TypeParagraph
.Style = "Heading 2"
.TypeText "Header 1.1"
.TypeParagraph
.Style = "No Spacing"
.TypeText "some text"
.TypeParagraph
.Style = "Heading 1"
.TypeText "Header 2"
.TypeParagraph
End With
这篇关于从Excel VBA写入Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文