Results 1 to 9 of 9
  1. #1
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44

    excel process not being terminated

    Can anyone look at the code below and give me some suggestions on why it would leave an excel.exe process running?



    Code:
       Dim OutPutFileName As String
       
       strPath = "C:\temp\test.xlsb"
       Set ApXL = CreateObject("Excel.Application")
       Set xlWBk = ApXL.Workbooks.Open(strPath)
       ApXL.Visible = False
     iRowCountA = Range(xlWBk.Sheets("sheet1").Range("A2"), xlWBk.Sheets("sheet1").Range("A2").End(xlDown)).Rows.Count
     
       ApXL.Visible = True
       OutPutFileName = "C:\temp\test- " & Format(Now, "yyyymmdd hhmmss") & ".xlsb"
        xlWBk.SaveAs FileName:=OutPutFileName
        Set xlWBk = Nothing
        Set ApXL = Nothing
    I have removed some other code but I know the line that starts with "iRowCountA......" is the culprit. If I comment it out that line there is no issues.

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    The code opens Excel and a workbook and then makes it visible and doesn't close Excel. Seems to me there should be a process running. Do you mean even after manually closing Excel a process is still running? I have encountered that as well, very aggravating. Not always sure what causes the process to persist.

    Why do you need the row count?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    allenjasonbrown@gmail.com is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Yes sorry. After manually closing the excel (which I want open when the application finishes) I still get an excel process running. It then causes an error if I try and run the Access application again.

    I use the row count to delete that number of rows from a different sheet.

  4. #4
    SteveH2508 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Try iRowCountA = ApXL.Range(xlWBk.Sheets("sheet1").Range("A2"), xlWBk.Sheets("sheet1").Range("A2").End(xlDown)).Ro ws.Count

    This problem is usually caused by unqualified references to Excel so it creates another instance of Excel which is left running.
    That is the only unqualified reference I can see (untested air-code)

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    You definitely should have ApXL.Quit before SET ApXL = Nothing.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Dal, I don't think that is actually required. If user wants to leave workbook open and continue working with it directly, that should be possible. The code can still release the variables. I have run code that opens Excel and workbook, edits the workbook and leaves the workbook open and I don't even bother releasing the variables and the process will terminate when I manually close Excel. Then there are times I have seen the process persist and figuring out why nearly drives me nuts, if I even ever figure out the why.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    June - wouldn't be absolutely required, but he's complaining about the process being left running... If that process has the potential to be run multiple times, and isn't going to quit the application, then it should be detecting whether the application is already running before creating a new one.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not sure even .Quit will assure the process is terminted. Seems I've run into that as well.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    The other possiblity is that it's quietly failing somewhere else, and not telling him it didn't get to the end of the code. The debug for that is changing the "on error" lines so that any errors will kick up a fuss.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import and process data
    By JOKER_ZA in forum Import/Export Data
    Replies: 13
    Last Post: 07-12-2013, 04:33 AM
  2. Help with Normalisation Process
    By supermessiah in forum Database Design
    Replies: 2
    Last Post: 02-26-2013, 12:36 PM
  3. Need help to simplify this process
    By shanea.kr in forum Access
    Replies: 1
    Last Post: 07-10-2012, 01:40 PM
  4. Efficient Process?
    By compooper in forum Database Design
    Replies: 1
    Last Post: 06-14-2011, 03:01 PM
  5. Quit/Terminated Employee Table
    By mwabbe in forum Access
    Replies: 6
    Last Post: 09-24-2010, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums