Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd problem exporting csv files from Excel.

Status
Not open for further replies.

Mightyginger

Programmer
Feb 27, 2003
131
0
0
US
So I have a spreadsheet that saves closing levels to CSV files. It was working fine until I rebooted the other day and ever since then every CSV file it saves is empty. Not sure if company IT have somehow "upgraded" my Excel without me knowing. We are running 2003 11.8169.8172 SP3.

If I step through the code and then manually save the csv file then it works fine. Any thoughts guys? I'm stumped.

Sub SaveClosingSpreads()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

ActiveSheet.Calculate

Dim Savepath As String

Dim ThisBook As Workbook
Set ThisBook = ActiveWorkbook
Savepath = "H:\tempfiles\"

''1m
Workbooks.Add
Sheets(1).Range("A1:A42").Value = ThisBook.Sheets("h.Publishing").Range("AT5:AT46").Value
Sheets(1).Range("B1").Value = "input"
Sheets(1).Range("B2:B42").Value = ThisBook.Sheets("h.Publishing").Range("AW6:AW46").Value
ActiveWorkbook.SaveAs FileName:=Savepath & "1m.csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

 


hi,

You do not need ThisBook...
Code:
Sub SaveClosingSpreads()
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    ActiveSheet.Calculate
    
    Dim Savepath As String

    Savepath = "H:\tempfiles\"
    
''1m
    With Workbooks.Add
        .Sheets(1).Range("A1:A42").Value = ThisWorkbook.Sheets("h.Publishing").Range("AT5:AT46").Value
        
        .Sheets(1).Range("B1").Value = "input"
        .Sheets(1).Range("B2:B42").Value = ThisWorkbook.Sheets("h.Publishing").Range("AW6:AW46").Value
        .SaveAs Filename:=Savepath & "1m.csv", FileFormat:=xlCSV, CreateBackup:=False
        .Close
    End With

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top