Code check

Miya

Well-known Member
Joined
Nov 29, 2008
Messages
662
hi what is wrong with this code? i have set ws as Sheet2

With ws
.Copy.SaveAs Filename:= _
"U:\TL\PV\CSV\test.csv", FileFormat:=xlCSV, _
CreateBackup:=False
.Close = False
End With
 
Ah, is that so ?

Thanks, I never thought that.

Shucks, no problem. I was hoping you might have info on that last bit about the date defaulting to mm/dd/yyyy from dd/mm/yyyy, as I am awefully clueless when it comes to different versions based on locale...
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Thanks Seiya and Mark for the explanation, it works now, just one question why is it when i have data 31/03/2009 in orignal data but when i open CSV file it changes to 3/31/2009

I think it depends on your country setting/locale of Windows.
 
Upvote 0
If you want to save csv and exactly how it looks then try
Code:
Sub test()
Dim temp As String, txt As String, i As Long, ii As Long
With Sheets("sheet2").UsedRange
    For i = 1 To .Rows.Count
        For ii = 1 To .Columns.Count
            temp = temp & "," & .Cells(i, ii).Text
        Next
        txt = txt & vbCrLf & Mid$(temp, 2) : temp = ""
    Next
End With
Open "U:\TL\PV\CSV\test.csv" For Output As #1
    Print #1, Mid$(temp, 3)
Close #1
End Sub
 
Upvote 0
I tried the code but when i opened the CSV file it was completely blank

If you want to save csv and exactly how it looks then try
Code:
Sub test()
Dim temp As String, txt As String, i As Long, ii As Long
With Sheets("sheet2").UsedRange
    For i = 1 To .Rows.Count
        For ii = 1 To .Columns.Count
            temp = temp & "," & .Cells(i, ii).Text
        Next
        txt = txt & vbCrLf & Mid$(temp, 2) : temp = ""
    Next
End With
Open "U:\TL\PV\CSV\test.csv" For Output As #1
    Print #1, Mid$(temp, 3)
Close #1
End Sub
 
Upvote 0
Run the code then return with the message.
Code:
Sub test()
Dim temp As String, txt As String, i As Long, ii As Long
With Sheets("sheet2").UsedRange
    MsgBox .Address
    For i = 1 To .Rows.Count
        For ii = 1 To .Columns.Count
            temp = temp & "," & .Cells(i, ii).Text
        Next
        txt = txt & vbCrLf & Mid$(temp, 2) : temp = ""
    Next
End With
MsgBox txt
Open "U:\TL\PV\CSV\test.csv" For Output As #1
    Print #1, Mid$(temp, 3)
Close #1
End Sub
 
Upvote 0
ok i got the message it has A3:S141 which is perfect as this my data range in source workbook, but the data is not there when i open the file

Run the code then return with the message.
Code:
Sub test()
Dim temp As String, txt As String, i As Long, ii As Long
With Sheets("sheet2").UsedRange
    MsgBox .Address
    For i = 1 To .Rows.Count
        For ii = 1 To .Columns.Count
            temp = temp & "," & .Cells(i, ii).Text
        Next
        txt = txt & vbCrLf & Mid$(temp, 2) : temp = ""
    Next
End With
MsgBox txt
Open "U:\TL\PV\CSV\test.csv" For Output As #1
    Print #1, Mid$(temp, 3)
Close #1
End Sub
 
Upvote 0
You need to use Share name for that drive that should begin with \\
Rich (BB code):
Sub test()
Dim temp As String, txt As String, i As Long, ii As Long
With Sheets("sheet2").UsedRange
    For i = 1 To .Rows.Count
        For ii = 1 To .Columns.Count
            temp = temp & "," & .Cells(i, ii).Text
        Next
        txt = txt & vbCrLf & Mid$(temp, 2) : temp = ""
    Next
End With
CreateObject("WScript.Shell").<WBR>CurrentDirectory = "\\server\TL\PV\CSV"
Open "test.csv" For Output As #1
    Print #1, Mid$(temp, 3)
Close #1
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,715
Members
449,118
Latest member
MichealRed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top