ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Convert only a particular worksheet to CSV (https://www.excelbanter.com/excel-programming/367507-vba-convert-only-particular-worksheet-csv.html)

[email protected]

VBA Convert only a particular worksheet to CSV
 
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.


Mallycat[_18_]

VBA Convert only a particular worksheet to CSV
 

try select instead of activat

--
Mallyca
-----------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...fo&userid=3551
View this thread: http://www.excelforum.com/showthread.php?threadid=56233


[email protected]

VBA Convert only a particular worksheet to CSV
 
Select doesn't work.

It says:
"Code Execution has been interrupted"



Mallycat wrote:
try select instead of activate


--
Mallycat
------------------------------------------------------------------------
Mallycat's Profile: http://www.excelforum.com/member.php...o&userid=35514
View this thread: http://www.excelforum.com/showthread...hreadid=562338



NickHK

VBA Convert only a particular worksheet to CSV
 
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

wrote in message
oups.com...
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.





All times are GMT +1. The time now is 12:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com