LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-open & save all delimited files

I have a macro that opens all delimited files and SHOULD save each fil
as an excel file. The new name should be the same as the delimite
file without the ".xl" in the end. In the code below the macro wil
open each file but will try to save the file as False.xls, if I accep
this name the code will run through each file in the directory and ope
& save each delimited file. This would be great but with each save th
macro saves the files as False.xls and asks to overwrite the False.xls
Any help would be much appreciated!

Thanks,
Ryan

Sub OpenAllDelimited()
'
'Open all delimited files from raw data directory in D:\Key West
'
Dim varr As Variant
Dim wkbk1 As Workbook
Dim wkbk As Workbook
Dim i As Long
Dim sh1 As Workbook
Dim sName As String
Dim sPath As String
Dim ub As Long
ReDim varr(1 To 1)
ub = 1
sPath = "D:\Key West\raw data\"
sName = Dir(sPath & "*.xl")
Do While sName < ""
ReDim Preserve varr(1 To ub)
varr(ub) = sName
ub = ub + 1
sName = Dir()
Loop

Set wkbk = ActiveWorkbook
For i = LBound(varr) To UBound(varr)
tName = sPath & varr(i)
Workbooks.OpenText Filename:=tName, _
Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited
TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False
FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6
1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)
Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1)
Array(20, 1), Array(21, 1), _
Array(22, 1), Array(23, 1), Array(24, 1))

Set wkbk1 = ActiveWorkbook

' Save workbook with name

wkbk1.SaveAs Filename = Left(wkbk1.Name, Len(wkbk1.Name) - 4) & ".xls"
FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False
_
CreateBackup:=False
wkbk1.Close SaveChanges:=False

Next
End Su

--
Message posted from http://www.ExcelForum.com

 
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
Excel files, periodically, taking a long time to save or open mavio Excel Discussion (Misc queries) 0 October 16th 09 04:43 PM
Excel Macro (open and save files with different drives) jxbeeman Excel Discussion (Misc queries) 1 September 25th 09 07:40 PM
How can I save all open excel files? Cobaum Excel Discussion (Misc queries) 3 September 1st 09 11:02 PM
How can I convert tab delimited files to pipe delimited? Jeremy Town Excel Discussion (Misc queries) 2 November 15th 07 04:29 PM
How do i save all open files in excel at once? ved_rocker Excel Discussion (Misc queries) 2 February 16th 06 10:11 PM


All times are GMT +1. The time now is 02:44 PM.

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"