Differences between MSWORD9.OLB and MSWORD8.OLB
Author |
Message |
Karri Kanga #1 / 4
|
 Differences between MSWORD9.OLB and MSWORD8.OLB
Hello everyone. I have a problem with Microsoft Word 9.0 Object Library. I have a VB program which opens a word document, finds certain words and replaces them. This program works perfectly in a computer where is Word 97 installed (which uses MSWORD8.OLB), but I have Word 2000 (which uses MSWORD9.OLB) in my computer and the code does not work. I can compile the code without problem. Following code causes program to crash when running, so I would appreciate any advise what changes I should make or try. Any text or code sample I have found from MSDN or anywhere else does not help :( In the code, if you have Word 97 or word 2000 code runs to 'Case "97"' branch. If you have Word 95 code runs to 'Case "95"' branch. Branch 'Case "97"' works if you have Word 97 installed, but it does not work if you have Word 2000 installed. What can I do? Sub Ole_Word_Replace(sTeksti1 As String, sTeksti2 As String) On Error GoTo Ole_Word_ReplaceVirhe gWordApp.Visible = True Select Case user1.Word Case "95" gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, 0, 0, 0, 0, 0, 1 Case "97" Dim sana As String gWordApp.ActiveDocument.Select With gWordApp.Selection.Find .Text = sTeksti1 .ClearFormatting .Replacement.Text = sTeksti2 .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With gWordApp.Selection.Find.Execute Replace:=wdReplaceAll Case Else gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, 0, 0, 0, 0, 0, 1 End Select Exit Sub Ole_Word_ReplaceVirhe: Ole_Word_Error "Ole_Word_Replace" Exit Sub End Sub
|
Sun, 11 Jul 2004 18:45:59 GMT |
|
 |
Karri Kanga #2 / 4
|
 Differences between MSWORD9.OLB and MSWORD8.OLB
Hello everyone. I have a problem with Microsoft Word 9.0 Object Library. I have a VB program which opens a word document, finds certain words and replaces them. This program works perfectly in a computer where is Word 97 installed (which uses MSWORD8.OLB), but I have Word 2000 (which uses MSWORD9.OLB) in my computer and the code does not work. I can compile the code without problem. Following code causes program to crash when running, so I would appreciate any advise what changes I should make or try. Any text or code sample I have found from MSDN or anywhere else does not help :( In the code, if you have Word 97 or word 2000 code runs to 'Case "97"' branch. If you have Word 95 code runs to 'Case "95"' branch. Branch 'Case "97"' works if you have Word 97 installed, but it does not work if you have Word 2000 installed. What can I do? Sub Ole_Word_Replace(sTeksti1 As String, sTeksti2 As String) On Error GoTo Ole_Word_ReplaceVirhe gWordApp.Visible = True Select Case user1.Word Case "95" gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, 0, 0, 0, 0, 0, 1 Case "97" Dim sana As String gWordApp.ActiveDocument.Select With gWordApp.Selection.Find .Text = sTeksti1 .ClearFormatting .Replacement.Text = sTeksti2 .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With gWordApp.Selection.Find.Execute Replace:=wdReplaceAll Case Else gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, 0, 0, 0, 0, 0, 1 End Select Exit Sub Ole_Word_ReplaceVirhe: Ole_Word_Error "Ole_Word_Replace" Exit Sub End Sub
|
Mon, 12 Jul 2004 15:50:13 GMT |
|
 |
alpin #3 / 4
|
 Differences between MSWORD9.OLB and MSWORD8.OLB
Have you tried creating a macro of what you want to do using the macro recorder in Word 2K to see what code is generated? This will usually give you a good starting point for writing your routines. There are definitely incompatibilities between the two object models and the Find method of the Range object is one of the incompatible areas. HTH, Bryan ____________________________________________________________ New Vision Software "When the going gets weird," Bryan Stafford "the weird turn pro."
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas On Wed, 23 Jan 2002 23:50:13 -0800, "Karri Kangas" Quote:
>Hello everyone. >I have a problem with Microsoft Word 9.0 Object Library. I >have a VB program which opens a word document, finds >certain words and replaces them. This program works >perfectly in a computer where is Word 97 installed (which >uses MSWORD8.OLB), but I have Word 2000 (which uses >MSWORD9.OLB) in my computer and the code does not work. I >can compile the code without problem. >Following code causes program to crash when running, so I >would appreciate any advise what changes I should make or >try. Any text or code sample I have found from MSDN or >anywhere else does not help :( >In the code, if you have Word 97 or word 2000 code runs >to 'Case "97"' branch. If you have Word 95 code runs >to 'Case "95"' branch. Branch 'Case "97"' works if you >have Word 97 installed, but it does not work if you have >Word 2000 installed. What can I do? >Sub Ole_Word_Replace(sTeksti1 As String, sTeksti2 As >String) > On Error GoTo Ole_Word_ReplaceVirhe > gWordApp.Visible = True > Select Case user1.Word > Case "95" > gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, >0, 0, 0, 0, 0, 1 > Case "97" > Dim sana As String > gWordApp.ActiveDocument.Select > With gWordApp.Selection.Find > .Text = sTeksti1 > .ClearFormatting > .Replacement.Text = sTeksti2 > .Replacement.ClearFormatting > .Forward = True > .Wrap = wdFindContinue > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchWildcards = False > .MatchSoundsLike = False > .MatchAllWordForms = False > End With > gWordApp.Selection.Find.Execute >Replace:=wdReplaceAll > Case Else > gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, >0, 0, 0, 0, 0, 1 > End Select > Exit Sub >Ole_Word_ReplaceVirhe: > Ole_Word_Error "Ole_Word_Replace" > Exit Sub >End Sub
|
Tue, 13 Jul 2004 00:08:07 GMT |
|
 |
Karri Kanga #4 / 4
|
 Differences between MSWORD9.OLB and MSWORD8.OLB
I have tried Macro recorder. I does similar code compared to my code and it works in the test document, but it does not work in my code. Reason is beyond me. I used macro recorder in Word 2000 and it did following code (as you can see, it is similar to my code in previous post). It works in the document it is created, but it does not work in my VB code. For some reason my VB code crashes always on the line '.Text = "3"', so for some reason after Find - function there is some incompatibility. Sub testi_2() ' ' testi_2 Makro ' Makro on nauhoitettu 18.1.2002, nauhoittaja: Karri Kangas ' ActiveWindow.ActivePane.SmallScroll Down:=-13 Selection.WholeStory Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "3" .Replacement.Text = "6" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub Quote: >-----Original Message----- >Have you tried creating a macro of what you want to do using the macro >recorder in Word 2K to see what code is generated? This will usually >give you a good starting point for writing your routines. >There are definitely incompatibilities between the two object models >and the Find method of the Range object is one of the incompatible >areas. >HTH, >Bryan >__________________________________________________________ __ >New Vision Software "When the going gets weird," >Bryan Stafford "the weird turn pro."
>Microsoft MVP-Visual Basic Fear and Loathing in LasVegas >On Wed, 23 Jan 2002 23:50:13 -0800, "Karri Kangas"
>>Hello everyone. >>I have a problem with Microsoft Word 9.0 Object Library. I >>have a VB program which opens a word document, finds >>certain words and replaces them. This program works >>perfectly in a computer where is Word 97 installed (which >>uses MSWORD8.OLB), but I have Word 2000 (which uses >>MSWORD9.OLB) in my computer and the code does not work. I >>can compile the code without problem. >>Following code causes program to crash when running, so I >>would appreciate any advise what changes I should make or >>try. Any text or code sample I have found from MSDN or >>anywhere else does not help :( >>In the code, if you have Word 97 or word 2000 code runs >>to 'Case "97"' branch. If you have Word 95 code runs >>to 'Case "95"' branch. Branch 'Case "97"' works if you >>have Word 97 installed, but it does not work if you have >>Word 2000 installed. What can I do? >>Sub Ole_Word_Replace(sTeksti1 As String, sTeksti2 As >>String) >> On Error GoTo Ole_Word_ReplaceVirhe >> gWordApp.Visible = True >> Select Case user1.Word >> Case "95" >> gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, >>0, 0, 0, 0, 0, 1 >> Case "97" >> Dim sana As String >> gWordApp.ActiveDocument.Select >> With gWordApp.Selection.Find >> .Text = sTeksti1 >> .ClearFormatting >> .Replacement.Text = sTeksti2 >> .Replacement.ClearFormatting >> .Forward = True >> .Wrap = wdFindContinue >> .Format = False >> .MatchCase = False >> .MatchWholeWord = False >> .MatchWildcards = False >> .MatchSoundsLike = False >> .MatchAllWordForms = False >> End With >> gWordApp.Selection.Find.Execute >>Replace:=wdReplaceAll >> Case Else >> gObjWord.MuokkaaKorvaa sTeksti1, sTeksti2, 0, 0, >>0, 0, 0, 0, 0, 1 >> End Select >> Exit Sub >>Ole_Word_ReplaceVirhe: >> Ole_Word_Error "Ole_Word_Replace" >> Exit Sub >>End Sub >.
|
Tue, 13 Jul 2004 14:42:56 GMT |
|
|
|