PDA

View Full Version : Bug word from access



No.Miss
08-06-2007, 07:35 AM
Hi,

I wrote this code which when runned just expplode my access.
(MSACCESS as generated error and will be closed by Windows...)
I use Office 2000.

Could some one try it and tell me if he got the same problem.



Dim appWord As Word.Application
Dim docTemp As Word.Document
Dim rngManip As Word.Range

Set appWord = New Word.Application
appWord.Visible = True

Set docTemp = appWord.Documents.Open("AnyWordFile")

Set rngManip = appWord.ActiveDocument.Range
rngManip.Find.Text = "1" 'KAAABOOOOM
rngManip.Find.Execute
rngManip.Select

Oorang
08-06-2007, 01:34 PM
I can recreate the error over here as well.

Charlize
08-07-2007, 02:14 AM
Maybe use Set rngManip = appWord.docTemp.Range instead of Set rngManip = appWord.ActiveDocument.Range

No.Miss
08-07-2007, 06:06 AM
Yeah, it was my first try but it did not work, so I tried some other things like using activedocument.

Thx for testing the code. Now I know I got to find some solution.

Since the same code worked in word,
I have found some hacky work around, just watch and be amazed :cool:



Public Sub test()
Dim appWord As Word.Application
Dim docTemp As Word.Document
Dim rngManip As Word.Range

Set appWord = New Word.Application
appWord.Visible = True

'Set docTemp = PrepareTempDoc(appWord, strModelFile, strFieldMail, strTable)
Set docTemp = appWord.Documents.Open("C:\Documents and Settings\sroberge\Mes documents\test bd\result.doc")
DynamicCoder docTemp
CustomSearch appWord, "[-END-]"

'Now I can manipulate that F****** range :)
appWord.Selection.Range.Bold = True

End Sub


Public Sub CustomSearch(appWord As Word.Application, strToFind As String)
appWord.Run "Finder", strToFind
End Sub


Public Sub DynamicCoder(docWord As Word.Document)
Dim vbc As VBComponent

Set vbc = docWord.VBProject.VBComponents.Add(vbext_ct_StdModule)
vbc.name = "TempMod"
vbc.CodeModule.InsertLines 4, _
"Public Sub Finder(strToFind as String)" & Chr(13) & _
"Dim rngManip as Word.Range" & Chr(13) & _
"Set rngManip = ActiveDocument.Range" & Chr(13) & _
"rngManip.Find.Text =" & "strToFind" & Chr(13) & _
"rngManip.Find.Execute" & Chr(13) & _
"rngManip.Select" & Chr(13) & _
"End Sub"

End Sub

Oorang
08-07-2007, 06:14 PM
Have you considered loading the whole document into a string or byte array and just looking for the word that way withing said string/byte array?

No.Miss
08-08-2007, 05:35 AM
No, never thought about it, since I wanted to use th word range function to easily extract the info I needed.

But thats a great idea, If I could fit the whole text into a string I could even use the split fonction to get what I need.