Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Jabaco Source |
|
1 |
See the class file below
|
Jabaco Source |
|
1 2 3 4 5 6 |
Dim oWord As New Word() oWord.visibleApp() oWord.openDoc "c:\\dummy\\test.doc" oWord.appendText "Blablabla" oWord.Terminate() Set oWord = Nothing |
This post has been edited 7 times, last edit by "StefanSchnell" (Jun 21st 2009, 5:26pm)
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
'-Begin Class Word-------------------------------------------------------- '-Constants------------------------------------------------------------- Private Const wdStory = 6 Private Const wdMove = 0 '-Variables------------------------------------------------------------- Private oWord As com#jacob#activeX#ActiveXComponent Private oDocs, oDoc As com#jacob#com#Dispatch '-Initialize------------------------------------------------------------ Private Sub Class_Initialize() Set oWord = New ActiveXComponent("Word.Application") End Sub '-Terminate------------------------------------------------------------- Public Sub Terminate() If oDoc <> Nothing Then closeDoc(False) End If oWord.invoke("Quit") Set oDoc = Nothing Set oDocs = Nothing Set oWord = Nothing End Sub '-visibleApp------------------------------------------------------------ '- '- Show Word application '- '----------------------------------------------------------------------- Public Sub visibleApp() oWord.setProperty("Visible", True) End Sub '-openDoc--------------------------------------------------------------- '- '- Open a document '- '----------------------------------------------------------------------- Public Sub openDoc(FileName As String) Set oDocs = oWord.getProperty("Documents").toDispatch() Set oDoc = com#jacob#com#Dispatch.call(oDocs, "Open", _ FileName).toDispatch() End Sub '-newDoc---------------------------------------------------------------- '- '- Create a new document '- '----------------------------------------------------------------------- Public Sub newDoc() Set oDocs = oWord.getProperty("Documents").toDispatch() Set oDoc = com#jacob#com#Dispatch.call(oDocs, "Add").toDispatch() End Sub '-closeDoc-------------------------------------------------------------- '- '- Close the document '- '----------------------------------------------------------------------- Public Sub closeDoc(SaveChanges As Boolean) If oDoc <> Nothing Then com#jacob#com#Dispatch.call(oDoc, "Close", SaveChanges) End If End Sub '-appendText------------------------------------------------------------ '- '- Add a text at the end of the open document '- '----------------------------------------------------------------------- Public Sub appendText(Text As String) Dim oSel As com#jacob#com#Dispatch Set oSel = oWord.getProperty("Selection").toDispatch() com#jacob#com#Dispatch.call(oSel, "EndKey", wdStory, wdMove) com#jacob#com#Dispatch.call(oSel, "TypeParagraph") com#jacob#com#Dispatch.call(oSel, "TypeText", Text) Set oSel = Nothing End Sub '-appendTextFromClipboard----------------------------------------------- '- '- Add a text from the clipboard at the end of the open document '- '----------------------------------------------------------------------- Public Sub appendTextFromClipboard Dim oSel As com#jacob#com#Dispatch Set oSel = oWord.getProperty("Selection").toDispatch() com#jacob#com#Dispatch.call(oSel, "EndKey", wdStory, wdMove) com#jacob#com#Dispatch.call(oSel, "TypeParagraph") com#jacob#com#Dispatch.call(oSel, "Paste") Set oSel = Nothing End Sub '-setTextToClipboard---------------------------------------------------- '- '- Set the whole text of the document to the clipboard '- '----------------------------------------------------------------------- Public Sub setTextToClipboard Dim oSel As com#jacob#com#Dispatch Set oSel = oWord.getProperty("Selection").toDispatch() com#jacob#com#Dispatch.call(oSel, "WholeStory") com#jacob#com#Dispatch.call(oSel, "Copy") Set oSel = Nothing End Sub '-checkSpelling--------------------------------------------------------- '- '- Execute the spell checking '- '----------------------------------------------------------------------- Public Sub checkSpelling() com#jacob#com#Dispatch.call(oDoc, "CheckSpelling") End Sub '-checkGrammar---------------------------------------------------------- '- '- Execute the grammar check '- '----------------------------------------------------------------------- Public Sub checkGrammar() com#jacob#com#Dispatch.call(oDoc, "CheckGrammar") End Sub '-End--------------------------------------------------------------------- |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Public Sub CheckSpelling_Click() Dim oWord As New Word() '-Create new document oWord.newDoc '-Set text from TextBox via ClipBoard in the Word document Clipboard.SetText(Form1.RichTextBox1.Text) oWord.appendTextFromClipboard '-Start check oWord.checkSpelling 'oWord.checkGrammar '-Copy corrected text to clipboard oWord.setTextToClipboard '-Terminate Word oWord.Terminate End Sub Public Sub GetCorrectedText_Click() Dim Text As String '-Copy corrected text from ClipBoard to TextBox Text = Clipboard.GetText() Form1.RichTextBox1.replaceText Text, 0, Len(Form1.RichTextBox1.Text) Form1.Refresh End Sub |
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography