divya_agarwal
Board Regular
- Joined
- Nov 24, 2008
- Messages
- 51
I'm using this code.
Sub OCRReader()
Dim doc1 As MODI.Document
Dim inputFile As String
Dim strRecText As String
Dim imageCounter As Integer
inputFile = Application.GetOpenFilename
strRecText = ""
Set doc1 = New MODI.Document
doc1.Create (inputFile)
doc1.OCR ' this will ocr all pages of a multi-page tiff file
For imageCounter = 0 To (doc1.Images.Count - 1) ' work your way through each page of results
strRecText = strRecText & doc1.Images(imageCounter).Layout.Text ' this puts the ocr results into a string
Next
fnum = FreeFile() 'function to write text file
Open "C:\Test\testmodi.txt" For Output As fnum
Print #fnum, strRecText
Close #fnum
'code to paste the data from text file to excel sheet
Dim txt As String, FileFolder As String, fs As Object
Dim w(), i As Long, c As Long, n As Long, x, FileName As String
FileFolder = "C:\Test\" 'change to suit
FileName = "testmodi.txt" 'change to suit
Set fs = CreateObject("Scripting.FileSystemObject")
txt = fs.opentextfile(FileFolder & FileName).readall
x = Split(txt, vbCrLf)
ReDim w(1 To UBound(x) + 1, 1 To UBound(Split(x(0), vbTab)) + 1)
For i = 0 To UBound(x)
n = n + 1
For c = 0 To UBound(Split(x(i), vbTab))
w(n, c + 1) = Split(x(i), vbTab)(c)
Next
Next
With Range("a3:e3")
.Resize(n, UBound(w, 2)).Value = w
End With
doc1.Close
End Sub
---------------
Here if i select the file which has table then i wanna paste that file in the excel also in the tabular form with borders.
Sub OCRReader()
Dim doc1 As MODI.Document
Dim inputFile As String
Dim strRecText As String
Dim imageCounter As Integer
inputFile = Application.GetOpenFilename
strRecText = ""
Set doc1 = New MODI.Document
doc1.Create (inputFile)
doc1.OCR ' this will ocr all pages of a multi-page tiff file
For imageCounter = 0 To (doc1.Images.Count - 1) ' work your way through each page of results
strRecText = strRecText & doc1.Images(imageCounter).Layout.Text ' this puts the ocr results into a string
Next
fnum = FreeFile() 'function to write text file
Open "C:\Test\testmodi.txt" For Output As fnum
Print #fnum, strRecText
Close #fnum
'code to paste the data from text file to excel sheet
Dim txt As String, FileFolder As String, fs As Object
Dim w(), i As Long, c As Long, n As Long, x, FileName As String
FileFolder = "C:\Test\" 'change to suit
FileName = "testmodi.txt" 'change to suit
Set fs = CreateObject("Scripting.FileSystemObject")
txt = fs.opentextfile(FileFolder & FileName).readall
x = Split(txt, vbCrLf)
ReDim w(1 To UBound(x) + 1, 1 To UBound(Split(x(0), vbTab)) + 1)
For i = 0 To UBound(x)
n = n + 1
For c = 0 To UBound(Split(x(i), vbTab))
w(n, c + 1) = Split(x(i), vbTab)(c)
Next
Next
With Range("a3:e3")
.Resize(n, UBound(w, 2)).Value = w
End With
doc1.Close
End Sub
---------------
Here if i select the file which has table then i wanna paste that file in the excel also in the tabular form with borders.