Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


Could anybody PLEASE help!??

I am trying to import a lot of seperate dat files into a single
worksheet, but every time i try and do this it opens up a seperate
sheet for each file!!

Is there any way i can import all the files, and also continue to
import as new ones are added

ANY help would be greatly appreciated


--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Import dat. file

Tuggers,

Excel opens a each file you open as a seperate worksheet.

You therefore have to copy the opened worksheet into the summary workbook.
This is quite easy to achive with VBA

The question is how do you sleect the files to import is it *.* or *.csv or
do you manually select them?


--
HTHs Martin


"tuggers" wrote:


Could anybody PLEASE help!??

I am trying to import a lot of seperate dat files into a single
worksheet, but every time i try and do this it opens up a seperate
sheet for each file!!

Is there any way i can import all the files, and also continue to
import as new ones are added

ANY help would be greatly appreciated


--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Import dat. file

did you do

Data=Import External Data = Import Data, then select Text and select your
file - walk through the import wizard and designate a location?

If you need code, turn on the macro recorder while you do it manually and
then adjust the recorded code.

--
Regards,
Tom Ogilvy

"tuggers" wrote in
message ...

Could anybody PLEASE help!??

I am trying to import a lot of seperate dat files into a single
worksheet, but every time i try and do this it opens up a seperate
sheet for each file!!

Is there any way i can import all the files, and also continue to
import as new ones are added

ANY help would be greatly appreciated


--
tuggers
------------------------------------------------------------------------
tuggers's Profile:

http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Import dat. file

Ron de Bruin has sample code to merge a bunch of .csv files into one, then
import it.

Maybe you could modify it to work with your .dat files.

http://www.rondebruin.nl/csv.htm



tuggers wrote:

Could anybody PLEASE help!??

I am trying to import a lot of seperate dat files into a single
worksheet, but every time i try and do this it opens up a seperate
sheet for each file!!

Is there any way i can import all the files, and also continue to
import as new ones are added

ANY help would be greatly appreciated

--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


Thanks for the interest guys

I have been trying to open them via the open option in the file menu o
the menu bar. This seems to be the only way to import dat. files??
Then when i had selected them all and gone through the import tex
screens, each file is imported as a seperate worksheet.

If there is a better way, id be happy to try it.
Is anybody able to supply me with the required vba code to import th
entire contents of the folder into a single worksheet?

I would greatly appreciate it

--
tugger
-----------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...fo&userid=2900
View this thread: http://www.excelforum.com/showthread.php?threadid=51483



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Import dat. file

Hi

i don't know whether this would work in your case, but give it try.

Sub MultiImporttest()
Dim flname
Dim filename
Dim FileNum As Integer
Dim Counter As Long, maxrow As Long
Dim WorkResult As String
Dim ws As Worksheet
On Error GoTo ErrorCheck
maxrow = Cells.Rows.Count
'Ask for the name of the file.
filename = Application.GetOpenFilename(FileFilter:="all file (*.*),*.*",
MultiSelect:=True)
'Check for no entry.
If VarType(filename) = vbBoolean Then
Exit Sub
End If

Application.ScreenUpdating = False
Application.EnableEvents = False

Counter = Cells(Cells.Rows.Count, "a").End(xlUp).Row
For Each flname In filename
FileNum = FreeFile()
Open flname For Input As #FileNum
Do While Seek(FileNum) <= LOF(FileNum)
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & flname
Line Input #FileNum, WorkResult
Set ws = Nothing
Set ws = ActiveSheet
ws.Select
Cells(Counter, 1) = WorkResult
If WorkResult < "" Then
Application.DisplayAlerts = False
Cells(Counter, 1).TextToColumns Destination:=Cells(Counter, 1),
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False
End If
Counter = Counter + 1
If Counter maxrow Then
MsgBox "data have over max rows: " & maxrow
Exit Sub
End If
Loop
'Close the open text file.
Close
Next

'Reset the application to its normal operating environment.
Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
ErrorCheck:
'Reset the application to its normal operating environment.
Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "An error occured in the code."
End Sub

keizi

"tuggers" wrote in message
...

Thanks for the interest guys

I have been trying to open them via the open option in the file menu on
the menu bar. This seems to be the only way to import dat. files??
Then when i had selected them all and gone through the import text
screens, each file is imported as a seperate worksheet.

If there is a better way, id be happy to try it.
Is anybody able to supply me with the required vba code to import the
entire contents of the folder into a single worksheet?

I would greatly appreciate it.


--
tuggers
------------------------------------------------------------------------
tuggers's Profile:

http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Import dat. file

Sorry, I've forgot to add one if statement.

"kounoike" wrote in message
...
Hi

i don't know whether this would work in your case, but give it try.

Sub MultiImporttest()
Dim flname
Dim filename
Dim FileNum As Integer
Dim Counter As Long, maxrow As Long
Dim WorkResult As String
Dim ws As Worksheet
On Error GoTo ErrorCheck
maxrow = Cells.Rows.Count
'Ask for the name of the file.
filename = Application.GetOpenFilename(FileFilter:="all file (*.*),*.*",
MultiSelect:=True)
'Check for no entry.
If VarType(filename) = vbBoolean Then
Exit Sub
End If

Application.ScreenUpdating = False
Application.EnableEvents = False

Counter = Cells(Cells.Rows.Count, "a").End(xlUp).Row


'===add a if statement below here
If Cells(Counter, "a") < "" Then
Counter = Counter + 1
End If
'===end

For Each flname In filename
FileNum = FreeFile()
Open flname For Input As #FileNum


keizi

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


WOW!!

That looks fantastic!!

The only trouble is im a bit of a vba novice!

The required dat. files are stored in a folder called 'Tricoder'
and the file is stored on T: drive (shared drive at my place of work)
Can you please show me where i would place this information.

Again, many thanks for the hel

--
tugger
-----------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...fo&userid=2900
View this thread: http://www.excelforum.com/showthread.php?threadid=51483

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Import dat. file

Hi

just run the macro, then a dialog for opening files appears. change to the folder
where files you want to import are, and select all files you want to import
- same way as you do when you use explore - and press OK button.
if you miss to select some files, run again the macro and select missing files
with worksheet where data already are selected, then it will add the data into
that worksheet.
That's all. But i'm not sure this will end up with what you want to get.

keizi

"tuggers" wrote in message
...

WOW!!

That looks fantastic!!

The only trouble is im a bit of a vba novice!

The required dat. files are stored in a folder called 'Tricoder'
and the file is stored on T: drive (shared drive at my place of work)
Can you please show me where i would place this information.

Again, many thanks for the help


--
tuggers
------------------------------------------------------------------------
tuggers's Profile:

http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


i tried using the code you supplied but its throwing up a syntax error
for the following part:

filename = Application.GetOpenFilename(FileFilter:="all file
(*.*),*.*",
MultiSelect:=True)

Any ideas of what to change to stop this??


--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


I have found the following information for importing files into a single
worksheet.

The trouble is i dont really understand what it all means!!

Could somebody please fill in the necessary changes for this to work??

Many, many thanks


--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Import dat. file

Hi

i wrote the code in one line. but when i pasted the code, my mailer inserted
the code new line automatically that caused syntax error. i think there is
more places which cause syntax error.
i'll put the code changed which would not cause syntax error when you copy.
But in case that there are syntax error again, please let me know.

Sub MultiImporttest()
Dim flname
Dim filename
Dim FileNum As Integer
Dim Counter As Long, maxrow As Long
Dim WorkResult As String
Dim ws As Worksheet

On Error GoTo ErrorCheck
maxrow = Cells.Rows.Count
filename = Application.GetOpenFilename _
(FileFilter:="all file(*.*),*.*", MultiSelect:=True)
If VarType(filename) = vbBoolean Then
Exit Sub
End If

Application.ScreenUpdating = False
Application.EnableEvents = False

Counter = Cells(Cells.Rows.Count, "a").End(xlUp).Row
If Cells(Counter, "a") < "" Then
Counter = Counter + 1
End If

For Each flname In filename
FileNum = FreeFile()
Open flname For Input As #FileNum
Do While Seek(FileNum) <= LOF(FileNum)
Application.StatusBar = "Importing Row " & _
Counter & " of text file " & flname
Line Input #FileNum, WorkResult
Set ws = Nothing
Set ws = ActiveSheet
ws.Select
Cells(Counter, 1) = WorkResult
If WorkResult < "" Then
Application.DisplayAlerts = False
Cells(Counter, 1).TextToColumns _
Destination:=Cells(Counter, 1), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=False, _
Comma:=True, Space:=False, _
Other:=False
End If
Counter = Counter + 1
If Counter maxrow Then
MsgBox "data have over max rows: " & maxrow
Exit Sub
End If
Loop
Close
Next

Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
ErrorCheck:
Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "An error occured in the code."
End Sub

keizi

"tuggers" wrote in message
...

i tried using the code you supplied but its throwing up a syntax error
for the following part:

filename = Application.GetOpenFilename(FileFilter:="all file
(*.*),*.*",
MultiSelect:=True)

Any ideas of what to change to stop this??


--
tuggers
------------------------------------------------------------------------
tuggers's Profile:

http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Import dat. file


That seems to work!!

I cant thank you enough..........

So much appreciated


--
tuggers
------------------------------------------------------------------------
tuggers's Profile: http://www.excelforum.com/member.php...o&userid=29000
View this thread: http://www.excelforum.com/showthread...hreadid=514838

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I import text file of cash flow to excel file then use formula Bumpa Excel Discussion (Misc queries) 2 May 28th 10 04:22 PM
How do I import text file, analyze data, export results, open next file Geoffro Excel Programming 2 March 6th 05 08:02 PM
Import text file into excel with preset file layout, delimeters VBA meldrape Excel Programming 7 June 15th 04 08:31 PM
open file dialog-select file-import worksheet Divinedar Excel Programming 1 January 16th 04 07:13 PM
Get External Data, Import Text File, File name problem Scott Riddle Excel Programming 1 July 11th 03 05:40 PM


All times are GMT +1. The time now is 11:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"