×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Task Manager process Excel.exe still running
2

Task Manager process Excel.exe still running

Task Manager process Excel.exe still running

(OP)
Using the code below the script loops through an Excel file and copys a ref number and pastes it to a cell further along the row (I'm just testing at the minute). Once its finished I try to open the spreadsheet but i get error 'File is already open exclusively by me do i want open it as read only'. Then if i try to run the code again another error appears saying i cant save the file do i want to save a copy? I check the Task Manager processes and Excel.exe is still open. So im thinking perhaps i need another line of code that closes the spreadsheet, am i right?

'========================================================
Sub Main()
Dim xlApp As Object
Dim xlWB As Object
Dim xlFile As String    
Dim CurrCell As string
Dim CurrRow As integer    
Dim iTotal as string    

iTotal = 0
xlFile = "C:\Test.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open(xlFile)

For CurrRow = 2 To xlWB.Sheets(1).UsedRange.Rows.Count
CurrCell = xlWB.Sheets(1).Cells(CurrRow, 1)
xlWB.Sheets(1).Cells(CurrRow, 14) = CurrCell
iTotal + CurrCell
next
displayalerts = false
xlWB.save
End Sub
'========================================================

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks

RE: Task Manager process Excel.exe still running

I would think you need to end with something like
xlwb.Close(SaveChanges:=False) in order to clear it out of memory.  Otherwise, you already have an instance of the workbook loaded into memory, even though your current program ends.

If you're not part of the solution, there's good money to be made in prolonging the problem.

RE: Task Manager process Excel.exe still running

Yes, you need to add a line to close the workbook, or what PinkGecko said.

CODE

Sub Main()
   Dim xlApp As Object, xlWB As Object, xlSheet As Object
   Dim xlFile As String, i As Long
   
   xlFile = "C:\Test.xls"
     
   Set xlApp = CreateObject("Excel.Application")
   Set xlWB = xlApp.Workbooks.Open(xlFile)
   Set xlSheet = xlWB.Sheets(1)
         
   For i = 1 To xlSheet.UsedRange.Rows.Count
      xlSheet.Cells(i, 14) = xlSheet.Cells(i, 1)
   Next i
   
   xlApp.DisplayAlerts = False
   xlWB.Save
   xlWB.Close
      
   Set xlSheet = Nothing
   Set xlWB = Nothing
   Set xlApp = Nothing
End Sub

RE: Task Manager process Excel.exe still running

(OP)
Thank you very much pinkgecko and WinblowsME , thats what i get for thinking it was harder than it actually is.

"Children are smarter than any of us. Know how I know that? I don't know one child with a full time job and children."...Bill Hicks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close