|
楼主 |
发表于 2018-2-21 19:29
|
显示全部楼层
Private Sub Command1_Click()
Dim wordApp As Word.Application
Dim myDoc As Word.Document
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
Set myDoc = wordApp.Documents.Add()
With wordApp.ActiveDocument.Styles(wdStyleNormal).Font
.NameFarEast = "仿宋_GB2312"
.Size = 16
End With
With wordApp.Selection.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(2.5)
.RightMargin = CentimetersToPoints(2)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(1.75)
.PageWidth = CentimetersToPoints(21)
.PageHeight = CentimetersToPoints(29.7)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeLineGrid
End With
With wordApp.Selection
.Font.Name = "仿宋"
.Font.Size = 16
.TypeText Text:="公司党支〔" & Year(Date) & "〕 号"
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
.Paragraphs(1).SpaceBefore = 200 '值设定范围195-200
.MoveDown Unit:=wdLine, Count:=1
.TypeParagraph
.MoveDown Unit:=wdLine, Count:=1
.TypeParagraph
.MoveDown Unit:=wdLine, Count:=1
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
.Font.Name = "方正小标宋简体"
.Font.Size = 22
.MoveDown Unit:=wdLine, Count:=1
.TypeParagraph
.ParagraphFormat.Alignment = wdAlignParagraphLeft
End With
wordApp.ActiveDocument.Shapes.AddConnector(msoConnectorStraight, 50, 300, 228, 0#).Select
With wordApp.Selection.ShapeRange.Line
.Weight = 1.75
.Visible = msoTrue
.Style = msoLineSingle
.ForeColor.RGB = RGB(255, 0, 0)
.Visible = msoTrue
End With
wordApp.ActiveDocument.Shapes.AddConnector(msoConnectorStraight, 320, 300, 228, 0#).Select
With wordApp.Selection.ShapeRange.Line
.Weight = 1.75
.Visible = msoTrue
.Style = msoLineSingle
.ForeColor.RGB = RGB(255, 0, 0)
.Visible = msoTrue
End With
wordApp.ActiveDocument.Shapes.AddShape(msoShape5pointStar, 285, 282, 30, 30).Select
With wordApp.Selection.ShapeRange
.Fill.ForeColor.RGB = RGB(255, 0, 0)
.Fill.Visible = msoTrue
.Fill.Solid
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.Visible = msoTrue
End With
wordApp.Selection.Collapse
wordApp.Selection.MoveDown Unit:=wdLine, Count:=3
myDoc.SaveAs "C:\Documents and Settings\Administrator\桌面\123.doc"
myDoc.Close True
wordApp.Quit
Set myDoc = Nothing
Set wordApp = Nothing
End Sub
上述代码能够运行,但保存的文档中设置的格式不对,如何手动保存结果是对的,但自动保存的结果就不对了,原因不明。请指点,谢谢!
|
|