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)
any ideas?
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