ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming multiple files from *.csv to *.txt (https://www.excelbanter.com/excel-programming/327609-re-renaming-multiple-files-%2A-csv-%2A-txt.html)

keepITcool

Renaming multiple files from *.csv to *.txt
 

Richard,

Have a look at the LOCAL argument on the OpenText method

try your files with local:=true and local:=false

introduced with ExcelXP.. and poorly documented, it may be what you're
looking for.






--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Richard Fuller wrote :

Unlike Excel 2000, which I used until the recent demise of my "old"
computer, Excel 2003 (WinXP) scrambles dates in *.csv files opened
with a VBA macro. The simple cure is to rename the *.csv files to
*.text before opening them with the Workbooks.OpenText method and
stipulate how the date string should be handled.

This is easy enough with only one file, but how can it be incorporated
with the GetOpenFilename(MultiSelect:=True)method? What I'd like to do
is have each selected file renamed to *.txt within the loop before it
is opened. I'd be forever grateful for some sample code to point me in
the right direction.

Here's the code I've been using for some years (called by the main
routine):


Sub OpenFilesWin98()
' Macro copied 07-12-2001 from Google Newsgroup -
microsoft.public.excel
' Written by Robert Rosenberg, MVP Excel http:\\ntware.com

' Shows Open File dialogue & opens selected CSV files

Dim ScrMode As Boolean
Dim lCount As Long
Dim szNames As Variant

ScrMode = Application.ScreenUpdating
lCount = 0
ChDir "C:\Documents and Settings\Owner\My Documents\DATA\" &
Left(sMth, 3)
szNames = Application.GetOpenFilename(MultiSelect:=True)

If IsArray(szNames) Then ' At least one file selected
Application.ScreenUpdating = False

' Loop through the array of files selected
For lCount = LBound(szNames) To UBound(szNames)
Workbooks.Open Filename:=szNames(lCount), UpdateLinks:=False,
ReadOnly:=True, Format:=2
Next lCount
End If

Application.ScreenUpdating = ScrMode

End Sub


TIA

Richard Fuller
Auckland, NZ



All times are GMT +1. The time now is 07:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com