I am looping through several worksheets in a file, copying information to another sheet (called wsCSV, which is stored in ThisWorkbook) and then I want to create a CSV file from this worksheet. After creating the sheet, the loop should continue to the next sheet.
Here is part of the code which should create the CSV:
' Create CSV file
If iControl = 1 Then
Application.DisplayAlerts = False
wsCSV.Copy
ActiveWorkbook.SaveAs Filename:=sDestin & "\" & sShName & ".csv", FileFormat:=xlCSV, CreateBackup:=True
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = True
End If
Anyway, when I proceed the code, SaveAs method starts creating "infinite" file, till it consumes all my disk space. I don't know how is it possible, as the file has 6 rows and 3 columns, so it should have 1-2 kb. I have to stop the process manually. Any thoughts? I tried this code in another macro and it worked OK.
Thanks!
Application.DisplayAlerts = Falseline until you have it working - it may be hiding some useful information. Step through your code in debug mode to see what's happening. Considering how small a snippet of code you've provided, I'd guess that whateverwsCSVis, it's much larger than you think. - FreeManCtrl-Endto see what the last used cell is. Try in Notepad (or Notepad++ or other text editor - multi GiB may be too big for Notepad), Look to see if there's some sort of unexpected random garbage at the end. Also, useCtrl-Endto ensure thatwsCSVis only as full as you think it is. - FreeMan