Error: "Call was rejected by callee"
-
Hi guys. In my project, I'm opening an MS Excel file and then trying to update some of the cells within it. The only catch however is this particular excel file contains two additional pivottables as well which contain a macro that executes code the instant the excel file is opened. So, due to the fact that I'm trying update cells at the same time this macro is trying to execute its code, I'm receiving an error which reads: "Call was rejected by callee" I've provided my code below. It fails on line 3 ("sheet = MSExcel..."): ---------------------------------------------------- workbook = excel.Workbooks.Open(filePath,0, false, 5, "", "", false, MSExcel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); sheet = (MSExcel.Sheets)workbook.Worksheets; worksheet = (MSExcel._Worksheet)sheet.get_Item(currentSheet); ------------------------------------------------------ Apparently, Excel is single-threaded so it can't handle two things at once. I noticed this because while debugging, if I set a breakpoint on my line of code that opens excel and "step into" the next few lines of code, everything works fine (i.e. I gave the macro enough time to execute its code first). So anyway, I was just wondering if anyone has ever come across this issue before and what can be done to correct it. Thanks in advance. -Goalie35
-
Hi guys. In my project, I'm opening an MS Excel file and then trying to update some of the cells within it. The only catch however is this particular excel file contains two additional pivottables as well which contain a macro that executes code the instant the excel file is opened. So, due to the fact that I'm trying update cells at the same time this macro is trying to execute its code, I'm receiving an error which reads: "Call was rejected by callee" I've provided my code below. It fails on line 3 ("sheet = MSExcel..."): ---------------------------------------------------- workbook = excel.Workbooks.Open(filePath,0, false, 5, "", "", false, MSExcel.XlPlatform.xlWindows, "",true, false, 0, true, false, false); sheet = (MSExcel.Sheets)workbook.Worksheets; worksheet = (MSExcel._Worksheet)sheet.get_Item(currentSheet); ------------------------------------------------------ Apparently, Excel is single-threaded so it can't handle two things at once. I noticed this because while debugging, if I set a breakpoint on my line of code that opens excel and "step into" the next few lines of code, everything works fine (i.e. I gave the macro enough time to execute its code first). So anyway, I was just wondering if anyone has ever come across this issue before and what can be done to correct it. Thanks in advance. -Goalie35
Here is a hack workaround. So, go ahead and skip this reply if you want a clean solution. In my experience I've found that Excell/Access/Word Macros are basically hack jobs anyway, so it probably won't hurt much hacking it up some more. Can you modify the macro that runs when the file is opened every time that you run that code? Alternatively modify the macro to check for a condition that you set to exit immdediately. Example: Step 1.) Modify or remove problem macro Step 2.) Run your code Step 3.) Restore problem macro Step 4.) Possibly run problem macro