+ Reply to Thread
Results 1 to 4 of 4

VBA Convert only a particular worksheet to CSV

  1. #1

    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.


  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394
    try select instead of activate

  3. #3

    Re: 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



  4. #4
    NickHK
    Guest

    Re: 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

    <[email protected]> wrote in message
    news:[email protected]...
    > 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.
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1