none
Error: -2147418111, Call was rejected by callee RRS feed

  • Question

  • I have a VB program that creates Word documents automatically. It has worked perfectly fine through prior versions of Windows and Word. We recently switched to Windows 8.1 and Word 2013. When creating a Word document, I get the error message "-2147418111, Call was rejected by callee"

    A portion of my code is below:

    Imports System
    Imports System.IO
    Imports System.Text
    Imports Microsoft.Office.Interop
    Imports Microsoft.Office.Interop.Word

    Public Class frmCreateDocs
        Public wdObj As Word.Application
        Public wdUnits1 As WdUnits = WdUnits.wdStory
        Public wdBk As WdGoToItem = WdGoToItem.wdGoToBookmark
        Public wdFmt As WdDocumentType = WdDocumentType.wdTypeDocument
        Public wdChar As WdUnits = WdUnits.wdCharacter
        Public wdLine1 As WdUnits = WdUnits.wdLine
        Public wdPara As WdUnits = WdUnits.wdParagraph
        Public wdExt As WdMovementType = WdMovementType.wdExtend

            With wdObj
                DocName = SetTemplate & "Lgl2010.dotx"
                .Documents.Add(Template:=SetTemplate & "Lgl2010.dotx", NewTemplate:=False, DocumentType:=WdDocumentType.wdTypeDocument)
                DocName = SetDir & "TrustAmend.docx"
                .Documents.Open(FileName:=SetDir & "TrustAmend.docx", ReadOnly:=True)
                .Selection.EndKey(wdUnits1, Extend:=wdExt)
                .Selection.Copy()
                .ActiveDocument.Close()
                .Selection.Paste()
            End With

    The error seems to occur when the .Selection.Endkey command is run.

    Any suggestions?


    Don Murray

    Monday, February 2, 2015 4:26 PM

Answers

  • Hello Don,

    Try to use the following line of code instead:

    Selection.EndKey(Unit:=wdUnits, Extend:=wdExtend)

    • Marked as answer by DWMEsq Monday, February 2, 2015 5:25 PM
    Monday, February 2, 2015 5:18 PM

All replies

  • Hello Don,

    Try to use the following line of code instead:

    Selection.EndKey(Unit:=wdUnits, Extend:=wdExtend)

    • Marked as answer by DWMEsq Monday, February 2, 2015 5:25 PM
    Monday, February 2, 2015 5:18 PM
  • Tried that and still got the same error message.

    Don Murray

    Monday, February 2, 2015 5:26 PM
  • Okay. Try to break the chain of calls, i.e. declare each property and method call on a single line of code. Thus, you will be able to find the exact property or method which fires the exception. Is it the EndKey function?
    Monday, February 2, 2015 5:36 PM
  • It definitely seems to be the endkey function.

    Don Murray

    Monday, February 2, 2015 5:38 PM
  • Okay. What code do you have now?
    Monday, February 2, 2015 6:21 PM
  • I changed it as you suggested.

            With wdObj
                DocName = SetTemplate & "Lgl2010.dotx"
                .Documents.Add(Template:=SetTemplate & "Lgl2010.dotx", NewTemplate:=False, DocumentType:=WdDocumentType.wdTypeDocument)
                DocName = SetDir & "TrustAmend.docx"
                .Documents.Open(FileName:=SetDir & "TrustAmend.docx", ReadOnly:=True)
                .Selection.EndKey(Unit:=WdUnits.wdStory, Extend:=wdExt)
                .Selection.Copy()
                .ActiveDocument.Close()
                .Selection.Paste()
            End With

    When I step through this routine, the error occurs at the endkey command. As you can likely tell, I have simply created a new document using an existing template, then I open a document which I want to copy from beginning to end to then paste into the newly created document.


    Don Murray

    Monday, February 2, 2015 6:31 PM