Importing Multiple Txt Files

Feb 27, 2008

I have part of macro to import a txt file into excel but it is not working as it should. It is giving me a message "This file is not a recognizable format" but its just a normal txt file. Also after it gives me this warning it will open in excel and with every new txt file it gives me this warning and after it opens it.

The code I am using is:

Sub su()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
sPath = "C:Historical" 'location of files
ChDir sPath
sFil = Dir("*.txt") 'change or add formats
Do While sFil "" 'will start LOOP until all files in folder sPath have been looped through Set oWbk = Workbooks.Open(sPath & "" & sFil) 'opens the file
Workbooks.OpenText (sPath & "" & sFil), Comma:=True, DataType:=xlDelimited
' do something
sFil = Dir
Loop ' End of LOOP
End Sub

In this line it gives me Runtime error 1004 Method 'Opentext' of object workbook failed:
Workbooks.OpenText (sPath & "" & sFil), Comma:=True, DataType:=xlDelimited

View 9 Replies


ADVERTISEMENT

Importing Multiple CSV Files Into Workbook

Dec 3, 2012

I have a workbook that contains over 100 worksheets with stock data and price information. It uses a screenscraper to update the workbook each day with the latest day's price, and then exports each of these .csv files into a local directory. The macro for this is working. In effect it is generating a price history file automatically in my absence for me that can be read by charting software.

What I would like though is a macro to loopthrough and backfill missing price histories on each worksheet. I have a source of .csv price histories already, but would like to avoid having to cut and paste each of the 105 files manually, as it may become a regular occurence.

Each worksheet that requires backfilling has the stock code in the cell "A2", so that can be used to search for the filename Range("A2") & ".csv"

This is as far as I have got - however it results in a runtime error (91) Object variable or With block variable not set, pointing to this line:-

VB: Workbooks.Open Filename:="D:FinancialData SheetsSpreadsheetsPension" & Ws.Range("A2").Value & ".csv"

VB:
Sub BackFillData()
Dim Ws As Worksheet
For i = 1 To 105
'Sheets.Add
ActiveSheet.Name = "Fund" & i

[Code] ......

View 2 Replies View Related

Importing Multiple CSV Files Into One Workbook

Jun 15, 2013

I am troubleshooting my macro that seems to cause a data shift with the Letter "F" when I import multiple CSV files into one spreadsheet. When I go outside of the macro and record a macro and import the CSV into a workbook it works perfectly fine. But there must be something in this code that is causing the shift:

VB:
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Public Function ChDirNet(szPath As String) As Boolean
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)

[Code] ....

I have attached an excel workbook that shows how the macro imports vs. a regular import. Why "F" is causing a shift in the data.

Data.xlsx

View 3 Replies View Related

Importing Multiple Text Files

Apr 16, 2008

This is a great bit of code (I found), to import multiple text files.

I have one small issue -

currently it imports with each file going to a new column, like this: text file1 A1:A4, txt file2 B1:B4, txt file3 C1:C4 etc etc

And eventually i risk running out of columns because I'm working with a lot of text files.

Can someone tell me what to do to modify this code so it imports like this? :
text file1 A1:D1, txt file2 A2:D2, txt file3 A3:D3 ETC ETC

.e.g. first file imports across row1, second file across row2 etc


Sub test2()
Dim myDir As String, fn As String, ff As Integer, txt As String
Dim delim As String, n As Long, b(), flg As Boolean, x, t As Integer
myDir = "\BP1MELIS001SHARED_DATAEVERYONESolutions IntranetPriceMasterlogs" '

View 9 Replies View Related

Importing Data From Multiple Text Files

Nov 22, 2006

I have about 1200 text files with data regarding different machines.These file contain a line called 'Validation date" and also the programe number on different line.

I need a macro which will extract this date for each program number and write in excel in two columns like program number and validation date.

I have tried with some of the macro help available on this site,but I have to do this one at a time.The time required doing this way is same as going in each text file and copy/pasting in excel.Is it possible to automate this process.

View 9 Replies View Related

Importing Specific Sheet Of Multiple XLS Files Into One

Nov 17, 2008

I know similar questions have been asked before, but I couldnt work out how it is done.
Basically I have several xls files with the same name, eg. "test" with an alternating number at the end. 1 - ....

each of these workbooks contain several sheets but all books are the same just with different information on it. each workbook has got a summary sheet in it, i want to import all summary sheets into a single workbook called summary. but each sheet should be imported as in individual sheet.

View 9 Replies View Related

Importing Multiple Text Files Into One Workbook

Apr 26, 2007

I am using excel 2003. I have more than 500 text file which are result of some numerical analysis. I have another bunches of the same file number. I can record and play around with macro.

What I want to do is
-copy selected cells from imported text file in excel and paste in new or in first opened excel file. I have recorded macro for one file including importing from text to excell, copy and paste the selected file (look the macro below). But I have more than 500 files and I want to do the macro the same thing for each file in one excell file. Do i have to make one macro for each file??, that takes much more time than manual import and copy paste. The cell position and range to copy is the same, but have to be pasted in new row (in one excel summery file). The file name of each text file is different and all are in the same folder.

Sub text_to_excel()

Workbooks.OpenText Filename:= _
"I:ResearchVALERI_germinationvaleri_slopevaleri_slope_COREL_DHPoutputDSCN2589.txt" _
, Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, _ ..................

View 9 Replies View Related

Importing Multiple .txt Files In One Excel Sheet From One Folder?

Sep 14, 2012

I have a folder in my D drive where I used to keep my Text files after downloading it from our support centeral. I want to Import all these Text files in one excel sheet in a way that data of each file got append in excel sheet below previous file data.I am trying to do this through FSO but unable to do the same.

View 1 Replies View Related

Importing Multiple Multi-Line Text Files

Apr 30, 2013

I'm trying to create a macro that will import multiple multiline text files.

I have tried another Macro from this site however that imports the each text file into one cell, but i need each line to be in a new cell and each file to be in the same sheet.

View 10 Replies View Related

Importing Selective Lines From Multiple Text Files

Jun 18, 2009

I have many text files basically with the same data from different dates. I am trying to select specific lines from each text, one that includes ".txt" which is the date, ex: "2008_308" and one that includes the word "PIXEL" and the following 5 lines after that.

I found a very similar post to mine and someone provided the script using VB for the question. It works, but it was only for one text file. I would like to use it for multiple text files. The files are all dated, i.e. "2008_308.txt". Although some of the dates are missing.

This is the script, from another posting, for importing selective lines from one text file:

Sub test()
Dim fn As String, txt As String, delim As String, a() As String
Dim i As Long, ii As Long, iii As Long, n As Long, x, y
fn = "c: est.txt" ' İChange here (File Path)
delim = vbTab ' İChange here (delimiter)
temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
x = Split(temp, vbCrLf)
ReDim a(1 To UBound(x) + 1, 1 To 100)
For i = 0 To UBound(x)
If InStr(1, x(i), "txt", 1) > 0 Then
n = n + 1 : y = Split(x(i), delim)
For ii = 0 To UBound(y)
a(n, ii + 1) = y(ii)..........................

View 9 Replies View Related

Add Another Worksheet & Continue Importing The Html Files Until There Are No More Files To Import

Jul 13, 2006

I'm using the following code to import thousands of html files into my spreadsheet. The code is working fine. Since I am importing thousands of files, when there is no more space on my worksheet, the code stops with an error message. I want to make this code add another worksheet & continue importing the html files until there are no more files to import.

Sub Master_Importer()
Dim I As Long
Dim strFilename As String
Dim strPath As String
strPath = "file:///C:/Documents and Settings/c/Desktop/New Folder/"
With Application.FileSearch
.LookIn = "C:Documents and SettingscDesktopNew Folder"
.FileType = msoFileTypeAllFiles
.Execute
For I = 1 To .FoundFiles.Count
strFilename = Mid(.FoundFiles(I), InStrRev(.FoundFiles(I), "") + 1)
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & strPath & strFilename _ .......................

View 5 Replies View Related

Importing Mutiple Files

Jul 14, 2009

Which is the best way import many (thousands of) files in text format into a single excel spreadsheet. Importing files with e.g. 50 lines to create 50 columns for rows for every file

View 2 Replies View Related

Importing And Analysing Files

Nov 6, 2008

We have an online system that generates xls dump files. These essentially contain a table with lots of information about every test case we perform. From this table I am interested in three fields: TestID, Location and TestCaseStatus. With these fields I need to generate : A drop down menu to filter by location
A table containing the count of each test case status for the relevant location. Every Row represents a TestID and the columns a status.

I was hoping you would be able to give me an idea of a good way to tackle this. My initial thought is that SQL maybe useful to import the desired table columns and then further filtering would have to be done through nested for loops. I'm sure you can suggest a better way though.

Also, if possible, I would prefer the raw data not to be displayed in my analysing spreadsheet - only the summary should be shown.

View 13 Replies View Related

Importing Text Files

Sep 25, 2002

I have a whole lot (hundreds) of .txt files that contain fixed width data that I need to convert to Excel format. I can open each file and step through the Text Import Wizard, then save it as an .xls file, but I'm wondering if there's a way to convert all the files in a given folder from .txt to .xls without having to open each one while (here's the kicker) still placing the data between the spaces on the .txt file into individual cells and columns like the wizard does.

View 9 Replies View Related

Importing CSV Files In A Worksheet

May 25, 2009

The Excel 2007 help menu claims that you can open a CSV file directly into a worksheet but I always get all the fields clumped-up into the first column.

After many tribulations I was able to import it through the Data import menu (text).

Could someone explain what I am doing wrong with the first method described above. It appears that the CSV converter is not working properly on my computer.

View 9 Replies View Related

Importing Very Large Text Files

Oct 28, 2008

So I am trying to use this VBA:

http://www.cpearson.com/excel/ImportBigFiles.aspx

It´s basically so I can important a very large log file, about 800,000 lines, many of them repeating, I want to import into Excel to better control the data.

I keep trying to import the data, and I cant get it to make me new sheets.

View 3 Replies View Related

Macro For Importing Text Files

Jan 16, 2014

Below is a macro I recorded for importing the text file AJ9285 into excel from an external location.

I would like to modify it so that excel will give me a prompt and I can type the text file name in.

Sub adt()
'
' adt Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;Z:AJ9285.ADT", _

[Code] ..........

View 2 Replies View Related

Importing Large Text Files

Feb 8, 2006

With reference to Importing large text file. i need to get large text files to automatically split across Excel sheets sheets while trying to Import. Can it be done only through Macros or is there any function in Excel itself.

View 7 Replies View Related

Skipping Empty Rows When Importing Files

Oct 30, 2006

Is there an easy way to revise the following code so that it imports ONLY the non-blank rows from files?

Sub ImportFiles()
Dim i As Integer, files As String, text As String

ChDir _
"C:Test"

Cells.Select
Range("A1").Activate
Selection.ClearContents
'Selection.QueryTable.Delete
Application. ScreenUpdating = False
i = 0
files = Dir("*.csv")
Do While files <> ""
Open files For Input As 1
Do While Not EOF(1)
i = i + 1
Line Input #1, text
Worksheets(1).Cells(i, 1) = text
Loop

View 9 Replies View Related

Searching And Importing JPEG Files And Paths Into Excel

May 23, 2012

Am creating a large medical teaching database on Excel that lists JPEG images (a few hundred) and the file paths for each image into separate Excel columns using a VBA macro.

The JPEG image filenames are numbered in ascending numerical format (i.e 1.jpeg).

View 1 Replies View Related

Importing Range From Worksheet Of Several Files Contained In A Folder

Jun 17, 2013

I have a folder with 8 files which have different names like John-s, Joe-K, Mary-j,....

There are 14 sheets in each file. One of the sheets in the files named Daily contain information in Range A5:G16 that I need to import from all 8 files into a separate file called Import.

View 4 Replies View Related

Extracting / Importing Tables From Several Word Files To Excel File

Jul 17, 2013

I have several word Files which has standard letter format and contains some tables which needs to be extracted / imported to Excel sheet

The File name is "employee name" which also needs to be extracted , if possible in same excel file.

Attached is the sample of word file. There are 3 tables which needs to be extracted

I have several files and I want to avoid doing it manually.

View 2 Replies View Related

Importing Text Files - Large Number Of Rows Blank After Each Import

Apr 5, 2012

I have a log that I regularly use to import text files, after each text file import it leaves a large number of rows blank that I have to delete before I add in the next text file import.

Any VBA method to detect this and remove the blank rows so that I dont have to keep checking to remove?

View 3 Replies View Related

Copy And Rename Files In VBA By Searching Multiple Folders For Files?

Jan 4, 2014

how I can loop through folders to select files starting with a certain word and copy all of them to a different folder and rename them. The folder structure is given below

Company 1(parent folder)
North South East(sub folder) West(sub folder)
Jan Feb Mar.... Dec Jan Feb Mar.... Dec Jan Feb Mar.... Dec Jan Feb Mar.... Dec

In the above structure, the files are present inside each folders Jan, feb...Dec under the regions North, South East n west. note that I have to select files starting with "Sales" and copy them into a new folder(say results) and rename copied files as Sales1.xls, Sales2.xls etc. (Files are not present in the folder company1, north, south, east and east.)

View 1 Replies View Related

Save Ranges In Multiple Files To Text Files

Dec 21, 2007

I have a excel file that I enter information into. I have code that saves the files to a certain folder with the name, date, and time stamp for the file name. At the end of the day I might have 3 to 15 excel files I have created that day and I would like to take information from certain cells (examle: L3, B6, B7, B8, G8, and so on) and create a txt file with all of the information in it.

Example:
12/20/2007
Your Name
123 Somewhere St.
Here, OH 45111
Home Visit

12/20/2007
Someone Else
345 Anywhere St.
There, OH 45211
Hospital Visit

View 9 Replies View Related

Importing Data From Multiple Tabs

May 6, 2009

I have an excel spread sheet with about 300 tabs. each sheet has the same column fields..I need to pull certain column fields ( the same fields ) out of each tab and export them to another spread sheet.

View 6 Replies View Related

Importing Data From Multiple Worksheets

Feb 23, 2012

Im trying to import data from multiple worksheets. The data from these worksheets are scattered throughout the different work sheets.

I would like to extract the specific data from each worksheet into a master template that ive created. 80% of the worksheets templates match my master template.

Is there any way to do this without taking 1 week to complete?

View 1 Replies View Related

Importing Multiple Excel Sheets To 1?

Feb 18, 2013

i want to import data from multiple excel files (with same kind of data) into a master file with each import want to display name of the file from which the data is imported in last column on all rows. for example if file 1 has 10 rows with file name abs, after import the macro show display on all 10 rows in a blank column abc. then import second file and its name and so on.

View 3 Replies View Related

Importing Macros Into Multiple Spreadsheets

Apr 19, 2007

Is there a way to automate the importing of macros into a list of files ? I have a number of files that I want to add some code to and was wondering if this could be automated as opposed to adding the code to each file manually as it's going to be a regular job.

I've written a routine to loop through the list of files and open them, I just want to know how, if possible, i can automatically import the required macros.

View 6 Replies View Related

Convert Multiple Files To Text Files

Sep 26, 2007

I have about 100 Excel files in one folder that need to be saved as text files. They can keep the same name, but simply need to be converted to text files. I'd like to use VBA for this and I can't find examples that do exactly that...or ones that my limited knowledge can handle.

Excel files exist in C:Source and ALL of them should be saved as text files in C:Destination. Maybe there is an easier way, but I thought for sure there was a routine I could use.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved