home *** CD-ROM | disk | FTP | other *** search
- Private Sub CreateWordDocument()
- 'sFilename is the file that we are going to create.
- Dim sFileName As String
- sFileName = "D:\test.doc"
- 'sText is what we will place in the file (the contents of the text box)
- Dim sText As String
- 'Create an instance of Word
- Dim objWord As Object
- Set objWord = CreateObject("word.basic")
- 'Prevents errors when spelling checker completes OK.
- On Error GoTo ErrorHandler
- sText = Text1.TEXT
- 'Clear the clipboard
- Clipboard.Clear
- 'Copy the text in Text1 to the clipboard
- Clipboard.SetText sText, 1
- 'Check the clipboard to ensure that the text is there
- If Clipboard.GetFormat(vbCFText) Then
- 'Using the word object
- With objWord
- 'Select File | New from the menu to create a new document
- .FileNew
- 'Paste the contents of the clipboard into the document
- .EditPaste
- 'Spell check the document. If the spell check is successful, error 51 occurs.
- .ToolsSpelling
- 'Select the text
- .EditSelectAll
- 'Copy it to the clipboard
- .EditCopy
- 'Save the word document (this creates a file)
- .FileSaveAs sFileName
- 'Close the word document
- .FileClose 2
- End With
- Else
- 'No text was in the text box
- MsgBox "There is nothing to save."
- End If
- 'Destroy the Word object
- Set objWord = Nothing
- 'Reset the text box to blank
- Text1.TEXT = ""
- Exit Sub
- ErrorHandler:
- Select Case Err
- Case 51
- Resume Next
- Case 5003
- MsgBox "That Command is not available at this time (disabled)"
- Case Else
- MsgBox Error$
- End Select
- End Sub
- Private Sub GetTextFromClipboard()
- Text1.TEXT = Clipboard.GetText(vbCFText)
- End Sub
-