bacon
02-10-2006, 05:09 AM
Hello
I would like a copy of a spreadsheet saved as a csv using the following metholodgy... data_472_20060209_1830.csv. Quite simple this will be static text "data_472_" followed by the year "2006", month "02" then day "09" followed by an underscore then followed by the time "1830".csv
The current VBA i am using simply saves the file as static text..(see below)
Can anyone help with amending the below VBA to save the spreadsheet as a CSV using the above metholodgy??
Thanks in advance
Private Function WriteFile(Range As Range, Index As Integer) As String
Dim sFile As String
Dim nFile As Integer
Dim nPage As Integer
Dim bFirstFile As Boolean
sFile = "c:\swapsstrips.xls"
nFile = FreeFile
Open sFile For Output As #nFile
bFirstFile = True
For nPage = 1 To Range.Columns.Count - 2
If UCase(Left(Range.Cells(Index + 1, nPage + 1).Value, 1)) = "Y" Then
If bFirstFile Then
bFirstFile = False
Else
Print #nFile, ""
Print #nFile, ""
End If
WriteRange nFile, Application.Range(CStr("Page" & nPage))
End If
Next nPage
Close #nFile
WriteFile = sFile
I would like a copy of a spreadsheet saved as a csv using the following metholodgy... data_472_20060209_1830.csv. Quite simple this will be static text "data_472_" followed by the year "2006", month "02" then day "09" followed by an underscore then followed by the time "1830".csv
The current VBA i am using simply saves the file as static text..(see below)
Can anyone help with amending the below VBA to save the spreadsheet as a CSV using the above metholodgy??
Thanks in advance
Private Function WriteFile(Range As Range, Index As Integer) As String
Dim sFile As String
Dim nFile As Integer
Dim nPage As Integer
Dim bFirstFile As Boolean
sFile = "c:\swapsstrips.xls"
nFile = FreeFile
Open sFile For Output As #nFile
bFirstFile = True
For nPage = 1 To Range.Columns.Count - 2
If UCase(Left(Range.Cells(Index + 1, nPage + 1).Value, 1)) = "Y" Then
If bFirstFile Then
bFirstFile = False
Else
Print #nFile, ""
Print #nFile, ""
End If
WriteRange nFile, Application.Range(CStr("Page" & nPage))
End If
Next nPage
Close #nFile
WriteFile = sFile