Abrir .dwg

HUGO SOUZA

12-08-2015 18:04:50

Olá!
A rotina abaixo abre desenhos em .dwg. Só que o Excel só abre o primeiro desenho, ou seja, se já existir um desenho aberto ele trava. Alguém pode ajudar?

Sub Abrir_Arquivo()
Dim DWG As String
Application.ScreenUpdating = False


If Right(ActiveCell.Value, 4) <> ".dwg" Or Right(ActiveCell.Value, 4) <> ".DWG" Then
MsgBox "Este arquivo não é válido.", vbCritical, "Atenção!"
Exit Sub
End If
DWG = ActiveCell.Value


'* É necessario habilitar a ref. AutoCAD #### Type Library
Dim ACAD As Object
Dim NewFile As Object
Dim MyAcadPath As String
Dim bReadOnly As Boolean

On Error Resume Next
Set ACAD = GetObject(, "ACAD.Application")
If (Err <> 0) Then
Err.Clear
Set ACAD = CreateObject("autocad.Application")
If (Err <> 0) Then
MsgBox "Could Not Load AutoCAD!", vbExclamation
End
End If
End If

'If you want to see AutoCAD on screen
'ACAD.Visible = True

MyAcadPath = DWG
bReadOnly = True
Set NewFile = ACAD.Documents.Open(MyAcadPath, bReadOnly)

If (NewFile Is Nothing) Then
ErrorMessage:
If NewFile = "False" Then End
MsgBox "Could not find the required spreadsheet that should be located at" & vbCr & MyAcadPath & vbCr & "Please rename or relocate the specified file as needed."
End
End If

'Close AutoCAD Process
'ACAD.Quit

Set ACAD = Nothing
Set NewFile = Nothing


End Sub

Mikel Silveira Fraga

12-08-2015 18:53:23

Hugo Souza, boa tarde.

Cara, não conheço muito de trabalhar com o AutoCad, mas vendo o código, acredito que possa utilizar o objeto NewFile como Array e, em cada camada, abrir um arquivo diferente.

Faça um estudo básico sobre Arrays que já vai lhe auxiliar na solução desta questão.

Abraços!!!