Results 1 to 5 of 5

Thread: Closing Generated MS Word Doc causes error 'Call was rejected by callee'

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2020
    Posts
    39

    Closing Generated MS Word Doc causes error 'Call was rejected by callee'

    Short intro - this is a Winform program which can generate MS Word reports.
    An error is created when a user trys to shut down the generating word report before the processing is complete (ie if its a long document and the user closes word)

    Code:
    System.Runtime.InteropServices.COMException
      HResult=0x80010001
      Message=Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
      Source=<Cannot evaluate the exception source>
      StackTrace:
    <Cannot evaluate the exception stack trace>
    Is there a way to prevent this error or process msword in the background so the user cant interact with it until its finished?

    Code:
    Dim oWord As Word.Application
            oWord = New Word.Application
            oWord.Documents.Add("\List.dot")
            oWord.Visible = True
            oWord.Activate
    
            With oWord.ActiveDocument
    
    ' do word stuff
    
            End With
            oWord = Nothing

  2. #2
    New Member
    Join Date
    May 2021
    Posts
    15

    Re: Closing Generated MS Word Doc causes error 'Call was rejected by callee'

    Direct solution : If it is a report, user should see it after the report is generated successfully.
    so, you should place oWord.Visible = True after 'do word stuff

    edit : this is exactly what you want, you don't need to set it visible at first.
    If do stuff with code, it can be done in invisible mode
    Last edited by fubao; Jun 13th, 2021 at 12:10 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2020
    Posts
    39

    Re: Closing Generated MS Word Doc causes error 'Call was rejected by callee'

    Do you have a simple example of what works? Im guessing its just the order of things, but trying this:

    Code:
    Dim oWord As Word.Application
            oWord = New Word.Application
            oWord.Documents.Add("\List.dot")
            oWord.Visible = false
            oWord.Activate
    
            With oWord.ActiveDocument
    
    ' do word stuff
    
            End With
            oWord.Visible = true
            oWord = Nothing
    causes an error at line : With oWord.ActiveDocument

    Code:
    System.Runtime.InteropServices.COMException
      HResult=0x800A11F9
      Message=Cannot activate application

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2020
    Posts
    39

    Re: Closing Generated MS Word Doc causes error 'Call was rejected by callee'

    Another possibility I would guess, is :

    Code:
    oWord.WindowState = Word.WdWindowState.wdWindowStateMinimize
    
            With oWord.ActiveDocument
    
    ' do word stuff
    
            End With
    oWord.WindowState = Word.WdWindowState.wdWindowStateMaximize
            oWord = Nothing

  5. #5
    New Member
    Join Date
    May 2021
    Posts
    15

    Re: Closing Generated MS Word Doc causes error 'Call was rejected by callee'

    Any stuff you want to do(eg. fill value, delete value, get value to use in your program)

    You don't open any workbook yet, then , there won't be any active workbook, use this to open workbook
    Code:
    oWord.Workbooks.Open("C:\xxxx\Desktop\xxx\xxx.xlsx")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width