- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everybody!
I know there is a lot been said about this error, tipically the code works aternatevely, so works fine, next time it doesn´t, then it does, then it doesn´t...
Even myself I´ve fix this errors in my code several times, but I cannot see what´s wrong this time :S, here is the line where it gets stopped:
Path = AutoCAD.AcadApplication.Path & "\Template\" & "Helloworld.lsp"
I know normally it happens due not specifying the whole property , but here I have tried everything already. What I do is putting a LSP file in typically "C:/Program files/Autodesk/AutoCAD 2014/Template/" where Autocad does not prompt any warning for being an unsafe location for loading a autolisp., but I´m not sure if in some other computer this path could change, so I build the complete path from the "Autocad.exe" file
Last time I had this error using two subs for opening and closing Autocad, specificall in the save as part. The problem stopped once I I did the following:
'Next line gives 462 error AutoCAD.Application.ActiveDocument.SaveAs (Nombre) 'Next line avoids 462 error acadApp.ActiveDocument.SaveAs (Nombre)
And the above code inside the whole sub:
'**********************************************AcadOpen**********************************************
Sub AcadOpen()
Dim acadApp As Object
Dim acadDoc As Object
'Comprueba si Autocad está abierto, si no está abierto crea una nueva instancia y la hace visible.
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
End If
' Comprobar otra vez si hay un objeto AutoCAD
If acadApp Is Nothing Then
MsgBox "Lo siento, no se puede abrir Autocad!", vbCritical, "AutoCAD Error"
Exit Sub
End If
On Error GoTo 0
'Si no hay un dibujo activo crear uno
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
End If
On Error GoTo 0
'tanto cerrar documento como autocadnecesitan que acadApp se inicialize con "set" y getobject como se hace arriba
'Cerrar documento
'acadApp.Documents.Close
'Cerrar autocad
'acadApp.Quit
'liberar objetos: no consigo quitar el error 462 con las siguientes 3 lineas
Set acadApp = Nothing
Set acadDoc = Nothing
On Error GoTo 0
End Sub
'********************'*********************Cerrar documento abierto********************'*********************
Sub cerrar()
Dim acadApp As Object
Dim Nombre As String
'obteniendo dirección completa del archivo que está en la celda A2
Sheets("Pruebas").Select
Nombre = Range("A2").Text
'inicializar la variable acadapp en el archivo que haya abierto.
Set acadApp = GetObject(, "AutoCAD.Application")
'guardar como
'Next line gives 462 error
AutoCAD.Application.ActiveDocument.SaveAs (Nombre)
'Next line avoids 462 error
acadApp.ActiveDocument.SaveAs (Nombre)
'Cerrar documento, no usándose ahora
'acadApp.Documents.Close
'Cerrar autocad
acadApp.Quit
End SubAnd to be honest I don´t see the logic in how I fixed it. I´ve been trying for hours to fix this error and for me it seems there is something fundamental about VBA that I´m missing... any idea?
Thank you very much in advance and forget my clumsiness believe it or not I´m stucked on something like this.
Pablo
Solved! Go to Solution.