So I'm trying to use the following code to open one drawing, save it to another name, do some stuff, then close it with a save. But I keep getting "Error saving the document" at the dwg.close. I think it might have something to do with a fumbled pass defining 'dwg' then saving it as something else, but I don't know... If chkElExBs.Value = Checked Then Set dwg = acad.Documents.Open(EDSpath & "ELEC\Drawings\_n04EMB.dwg") dwg.SaveAs (EDSpath & "arch\colorsend\HCYU_ELEC_BSMT_EXIST_n04EMB.dwg"), ac2000_dwg cmdDetXref 'call sub to detach xrefs strClrCode = "1" 'set the layer color for ELEC cmdLayFix 'call sub to manipulate layers dwg.Close (True) ' this is where End If Any ideas?
Do your subroutines save the drawing? Have you tried adding ThisDrawing.Save before dwg.Close? Seems too simple of an answer though. :|
I did try the ThisDrawing.Save - all it does is move up my error. I really think it has something to do with setting DWG = Drawing1, then saving as Drawing2. Possibly a "save as" does not change the value of DWG from "Drawing1" to "Drawing2". I'm going to try a do a copy Drawing1, Rename Drawing1 to Drawing 2, then open Drawing2. We'll see if that works...
The drawing I am opening is a 2000 format file created in 2004 (saved as 2000 from AutoCAD). It may be possible that the file being opened is already opened by another user, but the SaveAs happens so fast I can't catch any (Read Only) messages. BUT that is, in part what the SaveAs was supposed to be for... As always, much thanks for any tips...
Try adding a Set dwg = ActiveDocument before you close it and see if it helps ___________________________ Mike Tuersley CADalyst's AutoCAD Clinic Rand IMAGINiT Technologies
Thanks for all the replies - but to no avail. Even if I leave the 'dwg.SaveAs' drawings open, then try to close them manually, it tells me the drawing is write-protected. Argggh!
So this works: Dim FileCheck as New FileSystemObject Dim acad As New AcadApplication Dim dwg As AcadDocument FileCheck.CopyFile "H:\OldPath\Drawing1.dwg", "H:\NewPath\Drawing2.dwg", True 'Copy original to new location and new name, overwrite existing file Set dwg = acad.Documents.Open("H:\NewPath\Drawing2.dwg") 'Open new file <unload xrefs, change layer colors, etc> 'Do some stuff to the drawing dwg.close (true) 'close it with a save The issue only came up when the original file was open for editing. By copying it first, no problem. Thanks again for all the help!