Ending Excel.exe in Task Manager using VBA

Madingo

New Member
Joined
Mar 4, 2002
Messages
26
I have a client running a macro using excel 2003 over a terminal server. I am running into a problem where I can't save an excel sheet as a csv because it says that the file is being used by another user. I only have this problem over the term server. I have other people running the macro from their desktops without incident. I then need to go into task manager and end the excel.exe process and re-run---which then it works. Does anyone have any idea why I would have this problem over the term server and is there a way I can test to see if excel is open--and if it is close it prior to my activeworkbook.saveas line. Below are the lines where I am saving the xls file as a csv. I get the error on the activeworkbook.saveas

Workbooks(ImportMasterName & ".xls").Activate

ActiveWorkbook.SaveAs Filename:=ImportPath & ImportMasterName & ".csv", FileFormat:=xlCSV, CreateBackup:=False

Workbooks(ImportMasterName & ".csv").Close


like i said it works fine but only over the term server do i have the problem. Thanks for any help.

bill mahoney
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
1. You might be able to save the file as .xls with another name and then save the *copy* as .csv
2. I can understand you might get an error because .csv only allows a single sheet. If multiple sheets you presumably have the correct sheet active. Normally we get a warning message, and it may be this that gives the problem. Might try DisplayAlerts=False.
3. I have trouble understanding that you have an Excel macro running and need to check if Excel is running. Are you running a separate instance of Excel ?
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top