Consulting

Results 1 to 9 of 9

Thread: MODI.Document.Images(0).OCR fails for Office 2010 (on Windows 7)

  1. #1

    Cool MODI.Document.Images(0).OCR fails for Office 2010 (on Windows 7)

    Hi Guys,

    Goal: Convert legacy MS Word MODI-Document VBA-application from Office 2007 (on XP), to Office 2010 (on Windows 7, 32-bit).

    The VBA code below fails on the OCR method call. The error object message is:

    "Automation error. The object invoked has disconnected from its clients. "

    Dim midoc As MODI.Document
    Dim FiletoCheck As String
    Dim DocPages 
    Set midoc = New MODI.Document
    FiletoCheck = UserForm1.Label1.Caption
    midoc.Create FiletoCheck
    DocPages = midoc.Images.Count
    midoc.Images(0).OCR
    MODI was depricated in Office 2010. Microsoft published a solution to include Office 2007 MODI capability within Office 2010. I followed the instructions (for method 3):

    support.microsoft.com/kb/982760

    So here's the thing, why does the Count method work, but not the OCR method? See below.

    DocPages = midoc.Images.Count  '<==  This works perfectly!
    midoc.Images(0).OCR  '<== This method fails :dunno

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,442
    Location
    FWIW, I wouldn't have thought .Images(0) was a valid reference - you'd need at least .Images(1).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3

    Arrow

    Hi Guys,

    A bit more background.

    The legacy code works perfectly, for Office 2007, on Windows XP.

    The following line of code is good-to-go on XP, but not Win7.

    midoc.Images(0).OCR
    Since the original post yesterday, I've tinkered with the error handling, and when I change the error-handling to the following, there is a different error message.

    On Error GoTo 0
    The updated error message is, "Method 'OCR' of object 'IImage' failed".

    Ideas?

    Thanks,
    Andrew.

    ~

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    That link *seemed* to indicate that performing OCR operations in Office 2010 required using OneNote... is it possible that you simply can't use the .OCR method from within the Winword process in 2010?

    I'm totally unfamiliar with this area... but I'm guessing there are ramifications of Microsoft removing the MODI functionality in Word 2010. You may need to do some kind of CreateObject/GetObject functionality on the OneNote application and attempt to do your OCR from there.

  5. #5
    The application I'm working on is MS Word based. The users use Word, so it isn't an option to convert it to a OneNote application.

    You may need to do some kind of CreateObject/GetObject functionality on the OneNote application and attempt to do your OCR from there.

    Could you point me to some sample source code?

    However...

    The application works perfectly in XP. My prediction is that if I either add the appropriate 'OCR' library, or configure Windows 7 properly, the code will run correctly, as it did previously.

    As a developer, my first instinct is always to change the code, but because everything was working on the previous (Office 2007 + XP) platform, the task perhaps should be to enable to the new (Office 2010 + Win 7) platform to have the same capability as the previous platform. The question then becomes - how do I do this?

    Take care,
    Andrew.

  6. #6
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I'm not suggesting you convert to a OneNote application. But I am suggesting that your prediction is wrong (in terms of just getting the new platform to have the same capability as the old platform). The link you provided (and your own statements) indicate this functionality has been altered in Word 2010 (and removed, in some cases). And further, that link said that if you wanted to do OCR, you would need to do it in OneNote 2010 (not Word 2010).
    (quote from your link... bolding my own)
    Optical character recognition

    MODI also enables you to perform optical character recognition (OCR). By performing OCR, you can then copy text from a scanned image or from a fax into another location. To implement the functionality of this feature, use Microsoft OneNote 2010. To do this, follow these steps:
    In OneNote 2010, on the Insert tab, click Picture.
    Locate and then open the scanned file. The file is inserted into OneNote 2010 as a picture.
    Right-click the picture, click Copy Text from Picture, and then paste the information to another location.
    OneNote 2010 uses the XPS Document Writer printer driver to print to OneNote.
    So, from there, not knowing the process... I'm guessing that the reason you're able to refer to a MODI document within the Word VBA (by correctly getting a count of images) but unable to perform a particular method (.OCR) is because you might not be able to do that functionality directly from Word 2010, even though it works in Word 2007. (I don't think windows XP vs Win7 is making a difference here)

    I think you've got the pieces to potentially solve this, but I'm not sure. I'm guessing if it is possible, it's going to be a fair amount of work (I have no idea of what OneNote has, capability-wise, of external programmatic access).

    Do a google search on GetObject/CreateObject... there are a lot of samples. However, I would first re-read the link you provided, and see if you can't perform the manual steps of using OneNote 2010 to do OCR. And, of course, if there is a way to record macros in OneNote-- then you're well on your way.

    From there... you "may" be able to use CreateObject to start (from Word VBA) an instance of the OneNote application process, and then *maybe* use that process to perform your OCR function, and then take the results of that OCR process and dump it back into Word 2010.

    However, these are just general guidelines. I think what you're trying to do is going to be pretty difficult... and I frankly don't have the time to walk you through all of the various steps I would try to do. However, if you start posting sample documents, before and desired after, as well as proof-of-concept simplified code to try and do what you're doing... you may be able to get some specific help here.

    Or, I guess the above could be summed up with "I don't really know-- here's how I would approach it if someone was paying me to try and solve this..."

    Sorry I don't have a ready answer for you... but you're ultimately describing a "problem" (MODI .OCR method fails in Office 2010) which Microsoft has specifically said would be a problem in Word 2010. They've provided some steps to retrieve at least some of the functionality, but they're not promising anything.

    If I had to guess (and this whole post is full of guesses), I would bet that there were enough bugs in the process that they pulled it back from Word and dumped it elsewhere (OneNote)... so now a creative work-around probably needs to be worked up.

  7. #7
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Or maybe GetObject/CreateObject isn't the best place to start... you could check out this link.

    A quick glance at the One Note 14.0 object library didn't seem to indicate any programmatic methods about doing an OCR of an image, but that's probably where I'd start looking...

    http://code.msdn.microsoft.com/offic...utput-79bf3197

  8. #8
    VBAX Newbie james44's Avatar
    Joined
    Apr 2024
    Location
    united states
    Posts
    1
    Location
    The failure of MODI.Document.Images(0).OCR in Office 2010 on Windows 7 might stem from compatibility issues or missing dependencies. Ensure all required components are installed and updated. Consider alternative OCR solutions or seek assistance from technical support forums to troubleshoot and resolve the issue effectively.

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,232
    Location
    James44, Welcome to VBAX. Not sure what your intent is here given the thread is 12 years old, and the software has long moved on. Would you like to concentrate on issues more relevant please?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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