How do we Paste Tabular data in the Excel also in tabular form

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.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,215,208
Messages
6,123,644
Members
449,111
Latest member
ghennedy

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