Results 1 to 5 of 5

Thread: Excel Stays In Task Manager

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Excel Stays In Task Manager

    Why does Excel insist on staying in my task manager?

    This Does Work!

    For j = 1 To 5
    xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j).Select

    Set Wsheet = xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j)

    Wsheet.Range("D1").Value = ""

    Set Wsheet = Nothing
    xlApp.Quit
    Set xlApp = Nothing

    Wsheet.Range("F3", cells(DeleteRow, 6)).Value = ""

    Next j


    This Doesn't Work!

    For j = 1 To 5
    xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j).Select

    Set Wsheet = xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j)

    Wsheet.Range("D1").Value = ""
    Wsheet.Range("F3", cells(DeleteRow, 6)).Value = ""

    Set Wsheet = Nothing
    xlApp.Quit
    Set xlApp = Nothing

    Next j

  2. #2
    Lively Member rotcrules's Avatar
    Join Date
    Mar 2004
    Location
    SD
    Posts
    113
    !!!You Should Put this question in the VBA section of vbforums.com!!!

    but any way try putting "END" under the Unload form section.

    if it is that then your macro keeps going through a loop
    [Vbcode]If YourOpinion = WindowsIsCrap Then
    Kill Wndows
    Open Linux
    ElseIf YourOpinion = WindowsIsGreat Then
    Unload Me
    Else
    Get MSNTV
    End If[/vbcode]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Originally posted by rotcrules
    !!!You Should Put this question in the VBA section of vbforums.com!!!

    but any way try putting "END" under the Unload form section.

    if it is that then your macro keeps going through a loop
    I would put this question in the VBA section if I were using VBA. I'm writing everything in VB and accessing Excel in the background. I can't use end because I don't unload the form. This code resides in the main form of VB.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    You should never use End, as this will guarantee that objects (such as the Excel application) are not closed properly.

    here is a modified version of your code that should work properly:
    VB Code:
    1. 'I assume that xlApp is created above, and Workbooks are also loaded/created by this stage.
    2. For j = 1 To 5
    3.   xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j).Select
    4.  
    5.   Set Wsheet = xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j)
    6.  
    7.   Wsheet.Range("D1").Value = ""
    8.   Wsheet.Range("F3", [b]Wsheet.[/b]cells(DeleteRow, 6)).Value = ""
    9.  
    10.   Set Wsheet = Nothing
    11. Next j
    12.  
    13. [b]xlApp.Workbooks(LastMonthReport).Close SaveChanges:=False
    14. 'nb: if you want to save the changes you have done, set the parameter to True
    15. [/b]
    16. xlApp.Quit
    17. Set xlApp = Nothing
    The first issue (Wsheet.cells) would be a cause of this problem, as Cells is not a valid reference in VB (it is a member of a specific WorkSheet object). The next issue is closing/saving the Workbook - if you don't do it then Excel will ask the user what to do, and as it isn't visible it just stays running with no (visually)obvious reason.

    Ideally you should have an extra object variable for the WorkBook itself, but it may be ok as it is.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Excel Stays In Task Manager[RESOLVED]

    Originally posted by si_the_geek
    VB Code:
    1. 'I assume that xlApp is created above, and Workbooks are also loaded/created by this stage.
    2. For j = 1 To 5
    3.   xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j).Select
    4.  
    5.   Set Wsheet = xlApp.Workbooks(LastMonthReport).Worksheets("Week" & j)
    6.  
    7.   Wsheet.Range("D1").Value = ""
    8.   Wsheet.Range("F3", [b]Wsheet.<b>You should never use End, as this will guarantee that objects (such as the Excel application) are not closed properly.
    9.  
    10. here is a modified version of your code that should work properly:
    11. </b>cells(DeleteRow, 6)).Value = ""
    12.  
    13.   Set Wsheet = Nothing
    14. Next j
    15.  
    16. [b]xlApp.Workbooks(LastMonthReport).Close SaveChanges:=False
    17. 'nb: if you want to save the changes you have done, set the parameter to True
    18. [/b]
    19. xlApp.Quit
    20. Set xlApp = Nothing
    The first issue (Wsheet.cells) would be a cause of this problem, as Cells is not a valid reference in VB (it is a member of a specific WorkSheet object). The next issue is closing/saving the Workbook - if you don't do it then Excel will ask the user what to do, and as it isn't visible it just stays running with no (visually)obvious reason.

    Ideally you should have an extra object variable for the WorkBook itself, but it may be ok as it is. [/B]
    I have displayalerts set to none so I am not prompted when I quit excel therefore it automaticaly closes without saving. I have not tried the code you show with Wsheet.cells but I did rewrite the code this way and it worked (as you can see, without the use of cells). Thanks for your help!

    Wsheet.Range("F3:F" & DeleteRow).Value = ""

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