Just change dxf with dwg and you'll be good
2013 SOLIDWORKS API Help - Save Drawing Sheets as DXF Example (VBA)
It works pretty well. I made some changes to fit my needs.
I still need to make a last change. I want to add the custom property Rev from the model at the end of each dwg file.
I found the following lines. But it only allow me to add the Custom property Rev from the drawing to the filename.
Dim Rev As String
Rev = swModel.GetCustomInfoValue("", "Rev")
vSheetName = swDraw.GetSheetNames
For i = 0 To UBound(vSheetName)
bRet = swDraw.ActivateSheet(vSheetName(i))
bRet = swModel.SaveAs4(vSheetName(i) & "-" & Rev & ".dwg", swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)
Take a look at below - this will get you the property called Rev (not a configuration specific property)
Dim Rev As String: Rev = "" Rev = swModel.Extension.CustomPropertyManager("").Get("Rev") If Rev = "" Then swApp.SendMsgToUser "Revision property is empty. Cannot save file" Exit Sub End If
Your final save path must not contain any illegal characters.
If you want a full list way of the invalids, I advise you to use this free library I created to import .NET functionalities to VBA.
You can get a list of the illegal chars by calling the method IPathTools::GetInvalidPathChars().