View Single Post
 
Old 09-08-2015, 07:34 PM
Freedom20 Freedom20 is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Sep 2015
Posts: 4
Freedom20 is on a distinguished road
Default Using VBA to convert AutoCAD into WMF

I am trying to write a macro to open an AutoCAD dxf drawing and convert it to wmf and then import into the current Word document. Below is the code that I have written. My comments to the code are in blue.

Sub Convert_dxf()
Dim iRow As Integer
Dim AcadApp As Object
Dim SS 'As AcadSelectionSet Word will not let me declare this as a selection set


On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application")
If Err.Number <> 0 Then
Set AcadApp = CreateObject("AutoCAD.Application")
End If
AcadApp.Visible = True

AcadApp.Documents.Open ("C:\drawing.dxf")

Set SS = AcadApp.ActiveDocument.SelectionSets.Add("SS")
Set SS = Nothing
'SS.AcadApp.SelectAll
AcadApp.ActiveDocument.Export "C:\drawing", "WMF", SS
'at this point AutoCAD waits for me to select items on drawing.
'according to AutoCAD's help if the selection set is Nothing it is supposed to select the entire drawing.

AcadApp.ActiveDocument.Close savechanges:=False
' If AcadApp.Documents.Count = 1 Then
' AcadApp.ActiveDocument.sendcommand "Exit" & vbCr
' is there a way to close AutoCAD without using SendCommand?

' End If
Set AcadApp = Nothing
End Sub
I am open to other methods as long as the produce the same results. I do not want to take a screen shot or similar due to line quality issues.


Thank you in advance for any assistance you can provide.
Reply With Quote