HI,
We have a macro which is being used for converting the xls files to csv files., I need to change the output filenames of the generated .csv.. right now it is generating the filenames as tabname_timestamp for all the tabs present in the xls.
But I am looking for the below naming convention..if my xls name is SEP012011_DollarU_load.xls which has tabs like Monthly , weekly, the macro should generate the files as
SEP012011_DollarU_load.xls_Monthly
SEP012011_DollarU_load.xls_weekly
below is the piece of code which I tried to modify for the above outcome.., but i was not able to even compile the code
tempName = myPath & Trim(.Name) & "_" _
& Format(Time, "hhmmss") & ".csv"
And below is the macro which we are using .Please tell me how to add the xls name in the tempname variable so that the macro will generate the file formats as mentioned above.
Option Explicit
Sub testme01()
Application.ScreenUpdating = False
Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim tempWkbk As Workbook
Dim logWks As Worksheet
Dim tempName As String
Dim wks As Worksheet
Dim oRow As Long
'change to point at the folder to check
myPath = "C:\DollarU"
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If
'get the list of files
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop
If fCtr > 0 Then
oRow = 1
For fCtr = LBound(myFiles) To UBound(myFiles)
Set tempWkbk = Nothing
If tempWkbk Is Nothing Then
logWks.Cells(oRow, "A").Value = "Error Opening: " _
& myFiles(fCtr)
oRow = oRow + 1
Else
For Each wks In tempWkbk.Worksheets
With wks
If Application.CountA(.UsedRange) = 0 Then
'do nothing
Else
.Copy 'to a new workbook
tempName = myPath & Trim(.Name) & ".csv"
Do
If Dir(tempName) = "" Then
Exit Do
Else
tempName = myPath & Trim(.Name) & "_" _
& Format(Time, "hhmmss") & ".csv"
End If
Loop
End If
End With
Next wks
tempWkbk.Close savechanges:=False
End If
Next fCtr
End If
With logWks.UsedRange
.AutoFilter
.Columns.AutoFit
End With
Application.ScreenUpdating = True
End Sub
Best REgards
Bookmarks