MODI to Word

Randombard

Active Member
Joined
Jun 30, 2008
Messages
392
Hi All,

Having a play around with OCR and seeing If I can put something together to read documents and then map fields so we can upload them to our CRM.

My road block is using VBA to cause MODI to Send Text to word.

I can access the OCR results and "Print" each word to a cell with the following (cobbled together from various online discussions) but I would ideally like to make use of the "Send to Word" functionality as it will hold dome of the formatting and make it easier to map once I convert to a txt file and import to excel (have included that at the bottom the file paths are hard coded right now but that will change one I have this sorted)

Code:
Sub TestWords()
  
    Dim miDoc As MODI.Document
    Dim miWord As MODI.Word
    Dim strWordInfo As String
    Dim CountW
    Dim valueW As Range
    On Error GoTo catch
    
  ' Load an existing TIFF file.
  Set miDoc = New MODI.Document
  miDoc.Create "C:\Users\me\Desktop\test.tif"
  
  ' Perform OCR.
  miDoc.Images(0).OCR
   ' Retrieve and display word information.
   CountW = 1
   Set valueW = ActiveCell
  Set miWord = miDoc.Images(0).Layout.Words(CountW)
  Do Until CountW = miDoc.Images(0).Layout.Words.Count
    valueW.Value = miWord.Text
    CountW = CountW + 1
    Set valueW = valueW.Offset(1, 0)
    Set miWord = miDoc.Images(0).Layout.Words(CountW)
  Loop
catch:
  Set miWord = Nothing
  Set miDoc = Nothing

End Sub

any ideas?

Code:
Sub ConvertWordDocToTxt()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim tString As String, tRange As Word.Range
Dim p As Long, r As Long
    Workbooks.Add ' create a new workbook
    With Range("A1")
        .Formula = "Word Document Contents:"
        .Font.Bold = True
        .Font.Size = 14
        .Offset(1, 0).Select
    End With
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Open("C:\Users\me\Desktop\CV")
    ' example word operations
    With wrdDoc
        .SaveAs Filename:= _
        C:\Users\me\Desktop\CV.txt", _
        FileFormat:=wdFormatText, LockComments:=False, Password:="", _
        AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
        :=False, SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False _
        , AllowSubstitutions:=True, LineEnding:=wdCRLF
        .Close ' close the document
    End With
    wrdApp.Quit ' close the Word application
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    ActiveWorkbook.Saved = True
        With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\me\Desktop\CV.txt", _
        Destination:=Range("$A$2"))
        .Name = "Richard Austin CV"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 850
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Just in case anyone else wanted to know here is the code to put the text from MODI into a word document.

Code:
Sub PutInWord()
  
    Dim miDoc As MODI.Document
    Dim miWord
    Dim strWordInfo As String
    Dim CountW
    Dim valueW As Range
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
       
  ' Load an existing TIFF file.
  Set miDoc = New MODI.Document
  miDoc.Create "C:\Users\me\Desktop\test.tif"

  ' Perform OCR.
  miDoc.Images(0).OCR
   ' Retrieve and display word information.
   CountW = 1
   Set valueW = ActiveCell
  miWord = miDoc.Images(0).Layout.Text
  
      Set wrdApp = CreateObject("Word.Application")
  Set wrdDoc = wrdApp.Documents.Add
wrdApp.Visible = True
  With wrdDoc
    .Range.Text = miWord
    End With

catch:
  Set miWord = Nothing
  Set miDoc = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top