Copy data from .txt file to an Excel worksheet in a workbook that is not open

billfinn

Board Regular
Joined
Jun 7, 2018
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
I need to copy all of the data in a text file and then paste it into a specific worksheet in an excel workbook that is not open. Most of the info I have found is for the active worksheet, not what I am looking for.
Been working on this longer than I should have. It keeps quitting when it gets to the next line. Probably a syntax issue. The text file is just a dump from the AS400, I need to pull it into the specific worksheet 13 and then I'll continue on in formatting the sheet

Sub DATA_IMPORT()
Dim oFso: Set oFso = CreateObject("Scripting.FileSystemObject")
Dim oFile: Set oFile = oFso.OpenTextFile("H:\Quick Estimator Project\QPQUPRFIL_GJH_QDFTJOBD_907659_1.txt", 1)
Dim sText
sText = oFile.ReadAll
oFile.Close
Workbooks.Open ("H:\Quick Estimator Project\Estimating Tool 06-06-2018.xlsm")
Workbook.Sheets(13).Range("A:J:").Value = sText

End Sub

thanks,
Bill
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Bill,

Welcome to the MrExcel board.

See if this does what you want. Please note that I added a row number to your paste or else you will fill the entire columns ("A:J") with your text...

Code:
Sub DATA_IMPORT()


    Dim oFso: Set oFso = CreateObject("Scripting.FileSystemObject")
    Dim oFile: Set oFile = oFso.OpenTextFile("H:\Quick Estimator Project\QPQUPRFIL_GJH_QDFTJOBD_907659_1.txt", 1)
    Dim sText
    
    sText = oFile.ReadAll
    oFile.Close
    Workbooks.Open ("H:\Quick Estimator Project\Estimating Tool 06-06-2018.xlsm")
    Workbooks("Estimating Tool 06-06-2018.xlsm").Sheets(13).Range("A6:J6").Value = sText
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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