Consulting

Results 1 to 6 of 6

Thread: Bug word from access

  1. #1

    Thumbs up Bug word from access

    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

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    I can recreate the error over here as well.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Maybe use [VBA]Set rngManip = appWord.docTemp.Range[/VBA] instead of [VBA]Set rngManip = appWord.ActiveDocument.Range[/VBA]

  4. #4
    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

    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

  5. #5
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    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?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •