Results 1 to 20 of 20

Thread: HELP! Excel just won't quit!

Threaded View

  1. #13
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    This oughta do the trick, let me know if you have any questions with the coding :
    Code:
        Dim IntCount As Integer, ObjExcel As Object
        Set ObjExcel = GetObject(, "Excel.application")
        
        With ObjExcel
            .Workbooks.Add
            .Workbooks(2).Worksheets(1).Select
            'You'll need to select the wotrkbook before carrying out work on it
            '.Visible = False
            'you won't need this, it's automatically set to be hidden
            'by default, and you have to enter this as true for otherwise
            For IntCount = 0 To Int(Data2.Recordset.Fields.Count - 1)
                DoEvents
                Cells(1, IntCount + 1).Value = Data2.Recordset.Fields(IntCount).Name
            Next
            
            Range("A2").CopyFromRecordset Data2.Recordset
            .Cells(1, 1).CurrentRegion.EntireColumn.AutoFit
            .Sheets("Sheet1").Name = strReportName
            .displayalerts = False
            'This will stop any messages about overwiting and file being saved
            'from popping up on your screen and may be to do with your problem.
            .ActiveWorkbook.SaveAs FileName:="C:\Windows\Temp\XlFileName.Xls"
            'Course, this is the 2nd part of the error - your old code just shows
            'a path : ActiveWorkbook.SaveAs FileName:="C:\Windows\Temp\" and doesn't
            'specify a filename to save this as !!!!
            .Workbooks.Close
            .Quit
        End With
        
        Set ObjExcel = Nothing
    Last edited by alex_read; Apr 19th, 2001 at 04:30 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

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



Click Here to Expand Forum to Full Width