VBA Convert only a particular worksheet to CSV

J

jason.teen

Hi,

I am writing a script which converts xls to csv.
However, before it save / converts it to csv, it should only be
selecting the correct worksheet and not whatever is shown when opened
up.

I have tried this

Workbooks.Open fileName:=fileNames(i)
ActiveWorkbook.Worksheets("wksTest").Activate
ActiveWorkbook.SaveAs fileName:=Left(fileNames(i),
Len(fileNames(i)) - 4) & ".csv", FileFormat:=xlCSV
ActiveWorkbook.Close


However it doesn't like the Activate command there. Whats wrong with
it?

Thanks.
 
N

NickHK

Dim WB As Workbook

Set WB=Workbooks.Open fileName:=fileNames(i)
WB.Worksheets("wksTest").SaveAs fileName:=Left(fileNames(i),
Len(fileNames(i)) - 4) & ".csv", FileFormat:=xlCSV
WB.Close

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top