Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Split a 2gb csv file into two files

Guys,

I have a problem in that I need to link a text file (csv) to access, however
the text file exceeds 2gb.

Is there a way that I can breakup the file into to parts by using some vba
code?? I am not able to
have the text file re-generated into smaller tables, and am therefore stuck
as to how to split the csv file.

Anybody have any ideas?, anything would be appreciated

Cheers

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200607/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Split a 2gb csv file into two files

Ozzie,

You could try a macro like the one below - a little tweaking of the upper limits on the loops may
be needed....

HTH,
Bernie
MS Excel MVP

Sub SplitFiles()
Dim ReadStr As String
Dim FileName1 As String
Dim OrigFNum As Integer
Dim FileNumOut As Integer
Dim Counter As Double
Dim i As Integer
Dim j As Long

Counter = 1

FileName1 = Application.GetOpenFilename( _
"CSV Files (*.csv),*.csv", _
, "Pick the Original File")
If FileName1 = "" Then End

OrigFNum = FreeFile()
Open FileName1 For Input As #OrigFNum

For i = 1 To 10

FileNumOut = FreeFile()
Open "SplitFile" & i & ".csv" For Output Access Write As #FileNumOut

For j = 1 To 50000
Application.StatusBar = "Processing line " & Counter
Line Input #OrigFNum, ReadStr
Print #FileNumOut, ReadStr
Counter = Counter + 1
Next j

Close #FileNumOut

Next i

Close #OrigFNum

Application.StatusBar = False

End Sub



"Ozzie via OfficeKB.com" <u18021@uwe wrote in message news:6308b801e0978@uwe...
Guys,

I have a problem in that I need to link a text file (csv) to access, however
the text file exceeds 2gb.

Is there a way that I can breakup the file into to parts by using some vba
code?? I am not able to
have the text file re-generated into smaller tables, and am therefore stuck
as to how to split the csv file.

Anybody have any ideas?, anything would be appreciated

Cheers

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200607/1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Split a 2gb csv file into two files

Bernie,

Thanks, that was a big help

Cheers

Bernie Deitrick wrote:
Ozzie,

You could try a macro like the one below - a little tweaking of the upper limits on the loops may
be needed....

HTH,
Bernie
MS Excel MVP

Sub SplitFiles()
Dim ReadStr As String
Dim FileName1 As String
Dim OrigFNum As Integer
Dim FileNumOut As Integer
Dim Counter As Double
Dim i As Integer
Dim j As Long

Counter = 1

FileName1 = Application.GetOpenFilename( _
"CSV Files (*.csv),*.csv", _
, "Pick the Original File")
If FileName1 = "" Then End

OrigFNum = FreeFile()
Open FileName1 For Input As #OrigFNum

For i = 1 To 10

FileNumOut = FreeFile()
Open "SplitFile" & i & ".csv" For Output Access Write As #FileNumOut

For j = 1 To 50000
Application.StatusBar = "Processing line " & Counter
Line Input #OrigFNum, ReadStr
Print #FileNumOut, ReadStr
Counter = Counter + 1
Next j

Close #FileNumOut

Next i

Close #OrigFNum

Application.StatusBar = False

End Sub

Guys,

[quoted text clipped - 9 lines]

Cheers


--
Message posted via http://www.officekb.com
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 quickly split up worksheets into different files? amithere Excel Discussion (Misc queries) 4 December 10th 12 04:06 PM
how to split a large excel file into multiple smaller exel files. RM Excel Discussion (Misc queries) 2 February 17th 10 10:13 PM
Macro to split excel file into seperate files and then email LITTLE PETE Excel Discussion (Misc queries) 1 October 6th 08 01:37 PM
split one excel into two files. Miri Excel Discussion (Misc queries) 2 February 5th 07 01:20 PM
Split worksheet into new files Jason Excel Discussion (Misc queries) 3 April 20th 06 06:38 PM


All times are GMT +1. The time now is 08:31 PM.

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

About Us

"It's about Microsoft Excel"