Run-time error -2147418111 Automation error. Call was rejected by callee.

Run-time error -2147418111 Automation error. Call was rejected by callee.

Anonymous
Not applicable
8,314 Views
12 Replies
Message 1 of 13

Run-time error -2147418111 Automation error. Call was rejected by callee.

Anonymous
Not applicable

thanks for any help

little VBA test routine :

reading xls file with 5 tif file names, creating dwg with same ref name and attaching the same tif to the new dwg, then save and go next.

With the msgbox line active it works just fine. With the msgbox line ' as comment the error occurs.

 code attached

 

0 Likes
8,315 Views
12 Replies
Replies (12)
Message 2 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

don't see attached code 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 13

Anonymous
Not applicable

doc attached was a docx, here is the body (thanks) :

Dim ExcelApp As Object

Dim AcadApp As Object

 

Sub Tif_DWG()

 

        'Routine that reads raster (tif) filenames from xls sheet, creates a dwg based on each tif name

        'and attaches the same tif to that dwg. Author Nicolas Tobbackx - 11 april 2012

 

        'define Excel file variables       

                Dim appExcel As Excel.Application 'Excel application

                Dim wbExcel As Excel.Workbook 'Excel filename

                Dim wsExcel As Excel.Worksheet 'Excel sheet

       

                Set appExcel = Excel.Application

                Set wbExcel = appExcel.Workbooks.Open("c:\temp\test_tif_2dwg.xlsx")

                Set wsExcel = wbExcel.Worksheets("Sheet1")

       

        'define local variables       

                Dim i As Integer

                Dim Tif_feednewname As String

                Dim Newname As String

       

        'define AutoCad variables       

                Dim appAcad As AcadApplication

                Dim docAcad As AcadDocument           

                Dim Layout As AcadLayout

                Dim insertionpoint(0 To 2) As Double

                Dim rasterObj As AcadRasterImage

                Dim Mspace As AcadModelSpace

          

  'read xls file

            For i = 1 To 5

            Tif_feednewname = Cells(i, 1)          

           

           'create AutoCad file and insert tif in dwg

             Set docAcad = Application.Documents.Add

                insertionpoint(0) = 0: insertionpoint(1) = 0: insertionpoint(2) = 0

            'MsgBox "adding raster"

               ‘ZoomAll              

           

           Set rasterObj = docAcad.ModelSpace.AddRaster(Tif_feednewname, insertionpoint, 1, 0)

                rasterObj.ScaleFactor = 1

                Set Layout = docAcad.ModelSpace.Layout

            

                Newname = (Tif_feednewname & "_dwg")

 

                docAcad.SaveAs (Newname)

            Next i 

End Sub

0 Likes
Message 4 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

what should this line do?

Set Layout = docAcad.ModelSpace.Layout

 

At what line does the code raise up the exception?

Does the code crash at every drawing beginning with the first one or does it happen after some drawings were processed already?

Have you tried to pass a valide template-file when creating a new drawing with this statement:

Set docAcad = Application.Documents.Add

Is it a help if you close the drawing after inserting the image? Depending on size of TIFF, on memory and operating system you are using, on AutoCAD release it may be problematic to have multiple files opened having large images referenced.

 

- alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 13

Anonymous
Not applicable

Thank you very much for your reply.

The set layout line does nothing, it is indeed redundant

the code crashes on the first time. So no dwg gets created at all.

I tried with a template file but that does not change either.

I think the msgbox (and clicking OK ?) command sort of activates Autocad so Autocad is ready and listening and can start working. 

 

0 Likes
Message 6 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

so what is the line now that's execution results in the exception?

 

To get the AutoCAD application-window focused you can try to use this statement

AppActivate ThisDrawing.Application.Caption

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 13

Anonymous
Not applicable

Thanks again,

the activate command does not change anything

program blocks on the "set rasterobj" line .. (or any command in autocad that would appear there).

 

0 Likes
Message 8 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

sorry that I can't try the code now (as I think it would be a lot of work to get it reproduced) and so I only can show up some ideas (without testing it).

What about changing the statement to

Set rasterObj = docAcad.database.ModelSpace.AddRaster(Tif_feednewname, insertionpoint, 1, 0)

or this statement

Set rasterObj = ThisDrawing.ModelSpace.AddRaster(Tif_feednewname, insertionpoint, 1, 0)

 

>> or any command in autocad that would appear there

That I don't understand. As long as your code is running and you don't use SendCommand there could not be any commands called.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 9 of 13

Anonymous
Not applicable

thanks,

the "database" or "thisdrawing" versus (docAcad) argument does not change anything.

 

With any autocad command I mean for instance "zoom all" or regen or place circle etc.;

it's like Autocad does not "listen" (or is not active). The msgbox seems to activate.

So again, everything works fine WITH the msgbox and withe the 'commented msgbox (so without msgbox) if gives an error.

We tried on different machines here and same behaviour on all machines. We also tried wait, sleep, timer, ..

thanks,

Nico

0 Likes
Message 10 of 13

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

I have to avoid your Excel-handling (as this would use to much time for me), but tried the following code (as the problem seems to be isolated to the AddRaster-codeline) to come as close as possible to your problem-code-line.

 

I have a directory C:\TEMP and within that I have the files 1.TIF, 2.TIF, 3.TIF

Then I started this code, that creates for every image a new file and inserts then the correspondig TIF-file.

 

So the question is now: does that code run in your AutoCAD?

Public Sub test()
   Dim i As Integer
   Dim tAcadDoc As AcadDocument
   Dim tAcadApp As AcadApplication
   Set tAcadApp = ThisDrawing.Application
   Dim tInsPnt(2) As Double
   
   For i = 1 To 3
      Set tAcadDoc = tAcadApp.Documents.Add
      Dim tFileName As String
      tFileName = "C:\TEMP\" & CStr(i) & ".tif"
      Dim tImg As AcadRasterImage
      Set tImg = tAcadDoc.ModelSpace.AddRaster(tFileName, tInsPnt, 1, 0)
   Next
End Sub

It would also be great to know what AutoCAD release and servicepack you are running, also if plain AutoCAD or any vertical product base on AutoCAD.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 11 of 13

Anonymous
Not applicable

Hello,

Thank you very much indeed again for your help.

My colleague Francis Nahoé found a solution meanwhile with - i Guess-- A similar approach.

He added a timer called "tempo". see below

Wishing you all the best,

Nico Tobbackx -  Belgium

 

****

Sub Example_AddRaster(imageName As String)

 ' This example adds a raster image in model space.
 ' You should change this example to use
 ' a raster file on your computer.

 Dim insertionPoint(0 To 2) As Double
 Dim scalefactor As Double
 Dim rotationAngle As Double
 Dim rasterObj As AcadRasterImage


 insertionPoint(0) = 0#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
 scalefactor = 1#
 rotationAngle = 0

 On Error Resume Next
 ' Creates a raster image in model space
 Set rasterObj = ActiveDocument.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle)

 If Err.Description = "File error" Then
  MsgBox imageName & " could not be found."
  Exit Sub
 End If
 
 ZoomExtents
End Sub

 

Sub Pause(Tempo)
 Dim t As Date
 'Tempo en seconde
 t = Timer + Tempo:
 Do Until Timer > t: DoEvents: Loop
End Sub

 

Sub test()
 For i = 1 To 5
  Documents.Add
  Call Pause(1)
  Call Example_AddRaster("c:\Raster.tif")
 Next i
End Sub

Message 12 of 13

Anonymous
Not applicable

Thank you very very very much. I  was confused by this problem for many days. This  small code just solved my problem. Thank you.

谢谢,非常感谢。

      huaxiamengqing for china

0 Likes
Message 13 of 13

Anonymous
Not applicable
THANK YOU SO MUCH!!!

Adding the code for the paus solved my problem totaly !!!!!
0 Likes