Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 116
Default Automatic save as for CSV

Awesome, you always come through! Thanks Dave

Dave Peterson wrote:
I'm not sure how you have that list or what you do to open it, but this worked
ok for me with a single .CSV file.

Option Explicit
Sub testme()

Dim myFileName As String
Dim myPath As String
Dim wks As Worksheet
Dim TestStr As String
Dim iCtr As Long
Dim MaxTries As Long
Dim NewFileName As String
Dim NextFileName As String
Dim UseThisOne As Long

MaxTries = 99

myPath = "C:\my documents\excel\"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFileName = "Book1.csv"

Workbooks.Open Filename:=myPath & myFileName
Set wks = ActiveSheet

With wks
'do your manipulation here

'remove the .csv from the original filename
NewFileName = Replace(expression:=myFileName, _
Find:=".csv", _
Replace:="", _
compa=vbTextCompare)

'remove any dashes
NewFileName = Replace(expression:=NewFileName, Find:="-", Replace:="")

'look for the next available number
UseThisOne = -1
For iCtr = 1 To MaxTries
TestStr = ""
NextFileName = myPath & NewFileName & Format(iCtr, "00") & ".csv"
On Error Resume Next
TestStr = Dir(NextFileName)
On Error GoTo 0
If TestStr = "" Then
UseThisOne = iCtr 'found it!
Exit For
End If
Next iCtr

If UseThisOne < 0 Then
MsgBox "Error--ran out of numbers, file not saved!"
Else
.Parent.SaveAs Filename:=NextFileName, FileFormat:=xlCSV
End If

.Parent.Close savechanges:=False

End With

End Sub

I have a list of csv files that I need to open re-format and then close the
file and re-name so that I can import into Access. (Access doesn't recogonize

[quoted text clipped - 8 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/201004/1



--
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
Where does Save As Automatic Backup save its files? JoAnn Excel Discussion (Misc queries) 3 April 4th 08 08:48 PM
Automatic Save As Macro wrvadmin Excel Discussion (Misc queries) 3 January 23rd 08 05:48 PM
Automatic Save As gramps Excel Discussion (Misc queries) 2 April 4th 07 04:46 PM
Automatic Save and Exit duane Excel Discussion (Misc queries) 1 July 18th 06 10:32 AM
Automatic save workbook rufusf Excel Worksheet Functions 0 March 22nd 06 07:49 AM


All times are GMT +1. The time now is 08:16 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"