VBA Convert only a particular worksheet to CSV

  • Thread starter Thread starter jason.teen
  • Start date Start date
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.
 
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
 
Back
Top