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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
ws.SaveAs "U:\TL\PV\CSV\test.csv", xlCSV
ActiveWorkbook.Close False
<!-- / message -->
 
Upvote 0
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

should work, if it is true.
 
Upvote 0
should work, if it is true.

nope this is my code, i run the code from sheet 1 and when i open the csv file it copied sheet1 instead of sheet2

Sub csv()
Dim ws As Worksheet
Set ws = Sheets("Sheet2")
ws.SaveAs "U:\TL\PV\CSV\test.csv", xlCSV
ActiveWorkbook.Close True
End Sub

 
Upvote 0
It doesn't matter.

With or witout "With" statement, once you set the reference to Sheet2, it will always refer to that object.

You are saying

Sheets("sheet2").SaveAs ....

is saving Sheet1, that is impossible.
 
Upvote 0
It doesn't matter.

With or witout "With" statement, once you set the reference to Sheet2, it will always refer to that object.

You are saying

Sheets("sheet2").SaveAs ....

is saving Sheet1, that is impossible.

Thats whata happening, i tried again, i got the same results
 
Upvote 0
Miya,

Change this line:
Rich (BB code):
Sub csv()
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.Worksheets("Sheet2")
    
    ws.SaveAs ThisWorkbook.Path & "\xxxtest.csv", FileFormat:=xlCSV '"U:\TL\PV\CSV\test.csv", xlCSV
    
    ActiveWorkbook.Close False
    
End Sub

Hope this helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,911
Members
449,132
Latest member
Rosie14

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