Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Error: "Call was rejected by callee"

Error: "Call was rejected by callee"

Scheduled Pinned Locked Moved C#
helpdebuggingannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Goalie35
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • G 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

      B Offline
      B Offline
      bradsnobar
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups