Open workbooks and save as csv

  • Hi,


    I'm trying to open n number of workbooks from a specific folder, delete rows 1 to 4 and then close the workbook, saving it as a .csv file. The format of the files is always the same and I'm using Excel 2007.


    I have the following code:



    The code above opens the workbooks and deletes the required rows, but what I'm struggling with is the part to save the workbook as csv and then close without prompting. Is there a function to do this?


    Any advice would be greatly appreciated.


    Many thanks,


    Baron

  • Re: Open workbooks and save as csv


    use


    Code
    ''at start
    application.displayalerts = false
    
    
    ''at end
    application.displayalerts = true
  • Re: Open workbooks and save as csv


    Hi Ashu,


    thanks for your reply, but a runtime error (1004) appears stating Method 'SaveAs' of object '_workbook' failed. Debugging highlights this code:


    Code
    ActiveWorkbook.SaveAs Filename:= _
            (strP & "\*.csv") _
            , FileFormat:=xlCSV, CreateBackup:=False


    any ideas?

  • Re: Open workbooks and save as csv


    it should be


    Code
    ActiveWorkbook.SaveAs Filename:= _ 
    (strP & "\YOURFILENAME.csv") _ 
    , FileFormat:=xlCSV, CreateBackup:=False


    ur using (strP & "\*.csv") where the filename should be present asuming ur strp has the full path name and "\FILENAME.csv" the * should be replaced by the filename

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!