-
Using Word i nVB
Hi,
I want to be able to insert an instance of the word control as found in the Insertable Components list. It doesn't appear to have any properties or methods that I can use to load a docment though. Am I missing something? I don't want to use the OLE control because I want to insert it on an ActiveX Control.
Maybe someone might kow of a web-site where I can learn more about this?
Thanks for any help,
Johnny
-
Here's two bits of code that might help:
Code:
'===================================================================================
'Routine: WordPrint
'===================================================================================
'Inputs: String to be printed
'Outputs:
'Purpose: Prints passed-in text
'Sample Call: WordPrint txtText.Text
'Date: 8/28/00
'===================================================================================
' Revision History '
'===================================================================================
Public Sub WordPrint(TextToPrint As String)
Dim oWord As Object
Dim sMsg As String
Dim lCR As Long
Dim x As Long
Dim sLeft As String
Dim sRight As String
'Create an instance of a Microsoft Word Document Object
Set oWord = CreateObject("Word.Basic")
'Minimize the object
oWord.appminimize
'Create a new default document
oWord.filenewdefault
'Select any text in the new document and remove it
oWord.editselectall
oWord.editcut
'Insert the text from our text box into the word object
oWord.Insert TextToPrint
'Print the text moved to the Word document
oWord.fileprint
'Select any text in the new document and remove it
oWord.editselectall
oWord.editcut
'Close the instance of the MS Word object and remove it from memory
oWord.filecloseall 2
oWord.appclose
Set oWord = Nothing
End Sub
'===================================================================================
'Routine: SpellChecker
'===================================================================================
'Inputs: String to be checked
'Outputs: String with correct speeling
'Purpose: Checks spelling of passed-in text
'Sample Call: Text.Text = SpellChecker(txtText.Text)
'Date: 8/28/00
'===================================================================================
' Revision History '
'===================================================================================
Public Function SpellChecker(OldText As String) As String
Dim oWord As Object
Dim sMsg As String
Dim lCR As Long
Dim x As Long
Dim sLeft As String
Dim sRight As String
'Create an instance of a Microsoft Word Document Object
Set oWord = CreateObject("word.basic")
'Minimize the object
oWord.appminimize
'Create a new default document
oWord.filenewdefault
'Select any text in the new document and remove it
oWord.editselectall
oWord.editcut
'Insert the text from our text box into the word object
oWord.Insert OldText
'Go to the start of the document
oWord.startofdocument
'Run the spellchecker
On Error Resume Next
oWord.toolsspelling
On Error GoTo 0
'Select all the text in the word document and return to our program
oWord.editselectall
'Strip off the last character of the returned string
sMsg = Left(oWord.selection$, Len(oWord.selection$) - 1)
'Select any text in the new document and remove it
oWord.editselectall
oWord.editcut
'Close the instance of the MS Word object and remove it from memory
oWord.filecloseall 2
oWord.appclose
Set oWord = Nothing
'Set variable to length of returned text
lCR = Len(sMsg)
'Find each carriage return in the returned text, and replace it with a CRLF
For x = 1 To lCR - 1
If Asc(Mid(sMsg, x, 1)) = 13 Then
sLeft = Left(sMsg, x - 1)
sRight = Mid(sMsg, x + 1, Len(sMsg) - x)
sMsg = sLeft & vbCrLf & sRight
DoEvents
End If
Next x
'Reinsert text into text box on form
SpellChecker = sMsg
End Function
No need for the OLE control to do this either...