Private Sub Command1_Click()
Dim MyWord As Word.Application
Dim MyWordBook As Word.Document
Set MyWord = New Word.Application
Set MyWordBook = MyWord.Documents.Add("c:\test.doc") '打開test.doc用戶自定義的空白WORD文檔
MyWordBook.Activate
'3.放置宏代碼
With MyWordBook
'此處就可以插入宏代碼了
' Macro1 Macro
' 宏在 2009-9-20 由 adsl 錄制
'
Selection.Font.Size = 30
Selection.FormattedText.Bold = True
Selection.Font.Color = wdColorBlack
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:=" 通知"
Selection.Font.Color = wdColorRed
Selection.TypeParagraph
Selection.Font.Size = 22
Selection.TypeText Text:=" 今天下午三壹)"
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="("
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="班 全體同學四點鐘到操場進行體育課考試。"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:= _
" "
Selection.InsertDateTime DateTimeFormat:="yyyy-MM-dd", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Font.Size = 22
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.Font.Size = 16
Selection.TypeText Text:=" "
Selection.Font.Color = wdColorRed
End With
'4.保存,關閉文檔,退出
MyWord.Visible = False '設置WORD可見
MyWordBook.SaveAs FileName:="c:\aa.doc"
MyWordBook.Close
MyWord.Quit
Set MyWordBook = Nothing
Set MyWord = Nothing
MsgBox "操作完畢", vbOKOnly, "提醒"
unload me
End Sub