我的目标是写一个句子/段落,能够在同一个句子/段落中改变字体样式。这是在、Excel、和word文档中完成的(我相信您可以知道)。
示例:“请参阅表1。请注意表1是假定的。”
下面的代码似乎将整个句子设置为调用的最后一个wdStyleTypeCharacter。
Dim appWord As Word.Application
Dim objDoc As Word.Document
Set appWord = New Word.Application
appWord.Visible = True
Set objDoc = appWord.Documents.Add
Set Normal = objDoc.Styles.Add(Name:="Normal", Type:=wdStyleTypeCharacter)
Set Bold = objDoc.Styles.Add(Name:="Bold", Type:=wdStyleTypeCharacter)
Set Italic = objDoc.Styles.Add(Name:="Italic", Type:=wdStyleTypeCharacter)
With objDoc
With .Styles(Normal)
.Font.Name = "Arial Narrow"
.Font.Size = 11
.Font.Italic = False
.Font.Bold = False
End With
With .Styles(Bold)
.Font.Name = "Arial Narrow"
.Font.Size = 11
.Font.Italic = False
.Font.Bold = True
End With
With .Styles(Italic)
.Font.Name = "Arial Narrow"
.Font.Size = 11
.Font.Italic = True
.Font.Bold = False
End With
.Content.InsertParagraphAfter
.Range.Style = .Styles(Normal)
.Content.InsertAfter "Please see "
.Range.Style = .Styles(Bold)
.Content.InsertAfter "Table 1"
.Range.Style = .Styles(Italic)
.Content.InsertAfter ". Note Table 1 is assumed."
.Content.InsertParagraphAfter
End with
objDoc.Close savechanges:=wdSaveChanges
appWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
End Sub
发布于 2015-05-13 18:50:19
我不能百分之百确定你为什么要.selection word.application,但这解决了我的问题。如果有人能回答这个问题,这对我的基本理解来说将是很棒的(这是新的)。
Dim appWord As Word.Application
Dim objDoc As Word.Document
Set appWord = New Word.Application
appWord.Visible = True
Set objDoc = appWord.Documents.Add
With appWord.Selection
.Font.Name = "Arial Narrow"
.Font.Size = 11
.TypeText Text:="Please see "
.Font.Bold = wdToggle
.TypeText Text:="Table 1"
.Font.Bold = wdToggle
.Font.Italic = wdToggle
.TypeText Text:=". Note Table 1 is assumed."
End With
objDoc.Close savechanges:=wdSaveChanges
appWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
End Sub
希望这能在未来帮助到其他人。
https://stackoverflow.com/questions/30221808
复制相似问题