home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form WordVBAForm
- Caption = "Word VBA Demo"
- ClientHeight = 3750
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 9015
- LinkTopic = "Form1"
- ScaleHeight = 3750
- ScaleWidth = 9015
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command3
- Caption = "E X I T"
- Enabled = 0 'False
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 6735
- TabIndex = 4
- Top = 3120
- Width = 2175
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 3285
- Left = 135
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 2
- Text = "WordVBA.frx":0000
- Top = 345
- Width = 6480
- End
- Begin VB.CommandButton Command2
- Caption = "Massage DOC file"
- Enabled = 0 'False
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 6720
- TabIndex = 1
- Top = 2505
- Width = 2175
- End
- Begin VB.CommandButton Command1
- Caption = "Create DOC file"
- BeginProperty Font
- Name = "Verdana"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 495
- Left = 6720
- TabIndex = 0
- Top = 1905
- Width = 2175
- End
- Begin VB.Label Label1
- Caption = "Enter Your Text Here"
- BeginProperty Font
- Name = "Verdana"
- Size = 9.75
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 285
- Left = 150
- TabIndex = 3
- Top = 15
- Width = 2475
- End
- Attribute VB_Name = "WordVBAForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim WordApp As Word.Application
- Private Sub Command1_Click()
- Dim thisDoc As Document
- Dim thisRange As Range
- Dim prnTime As Date
- Dim breakLoop As Boolean
- Me.Caption = "Creating document..."
- Set thisDoc = WordApp.Documents.Add
- thisDoc.Range.InsertBefore "Document Title" & vbCrLf & vbCrLf
- Set thisRange = thisDoc.Paragraphs(1).Range
- thisRange.Font.Bold = True
- thisRange.Font.Size = 14
- thisRange.ParagraphFormat.Alignment = wdAlignParagraphCenter
- thisRange.InsertAfter "This sample document was created automatically with a Visual Basic application." & vbCrLf
- thisRange.InsertAfter "You can enter additional text here " & vbCrLf
- thisRange.InsertAfter vbCrLf & vbCrLf
- thisRange.InsertAfter "This project was created for Mastering VB5 "
- thisRange.InsertAfter "(Sybex, 1997) and was tested with Word 97."
- thisRange.InsertAfter vbCrLf
- thisRange.InsertAfter "Your text follows"
- thisRange.InsertAfter Text1.Text
- Me.Caption = "Saving document..."
- thisDoc.SaveAs "c:\sample.doc"
- Me.Caption = "Printing document..."
- thisDoc.PrintOut True, True
- prnTime = Time
- breakLoop = False
- While WordApp.BackgroundPrintingStatus <> 0 And Not breakLoop
- If Minute(Time - prnTime) > 1 Then
- Reply = MsgBox("Word is taking too long to print." & vbCrLf & "Do you want to quit?", vbYesNo)
- If Reply = vbYes Then
- breakLoop = True
- Else
- prnTime = Time
- End If
- End If
- Wend
- WordApp.Quit
- MsgBox "Document saved and printed!"
- Command2.Enabled = True
- Command3.Enabled = True
- Me.Caption = "Word VBA Demo"
- End Sub
- Private Sub Command2_Click()
- Dim thisDoc As Document
- Dim thisRange As Range
- WordApp.Documents.Open ("c:\sample.doc")
- WordApp.Visible = False
- Set thisDoc = WordApp.ActiveDocument
- thisDoc.Content.Find.Execute FindText:="VB5", ReplaceWith:="VB6", Replace:=wdReplaceAll
- While thisDoc.Content.Find.Execute(FindText:=" ", Wrap:=wdFindContinue)
- thisDoc.Content.Find.Execute FindText:=" ", ReplaceWith:=" ", Replace:=wdReplaceAll, Wrap:=wdFindContinue
- Wend
- End Sub
- Private Sub Command3_Click()
- WordApp.Quit
- Set WordApp = Nothing
- End
- End Sub
- Private Sub Form_Load()
- Set WordApp = CreateObject("Word.Application")
- WordApp.Visible = False
- End Sub
-