Olhado_ Posted July 5, 2009 Posted July 5, 2009 I have this vba code, which I call from vb program with the following batch file. It works fine, except that once the vba program is complete it needs the user to close AutoCAD to continue. Is there any way I can have a vba program close AutoCAD? I tried using SendCommand "Exit" and it seems to just confuse AutoCAD. Batch File: call "C:\[...]\Acad.exe" /b "C:\plot\plot.scr" exit VBA Code: Public Sub Main() Dim strPlotSize As String Dim strPrinterType As String Dim docCurrentDrawing As AcadDocument Dim strFileName As String Dim acState As AcadState Dim objWin As Object ' Reserved for Debugging 'UserForm1.Show ' Read printer preferances Read_File ("C:\plot\plot_config.txt") strPrinterType = cDL(1) cDL.Remove (1) strPlotSize = cDL(1) cDL.Remove (1) ' Read list of files Read_File ("C:\plot\batch_plot.txt") ' Open in read-only mode and run LISP file For intList = 1 To intCount Set docCurrentDrawing = Application.Documents.Open(cDL.Item(intList), vbReadOnly) strFileName = Replace(docCurrentDrawing.Name, ".dwg", ".pdf") docCurrentDrawing.SendCommand ("CADLock" & vbCr) GoTo Wait Continue: ' Print Page and close document ReleasePrint strPrinterType, strPlotSize docCurrentDrawing.Close (False) For lngVbaHold = 1 To 50000 DoEvents Next ' Close printed PDF document CloseApp strFileName, "" Next For intList = 1 To intCount CloseApp Replace(cDL.Item(intList), ".dwg", ".pdf"), "" Next On Error Resume Next Application.ActiveDocument.SetVariable "FILEDIA", 1 End ' End of Program Wait: Set acState = Application.GetAcadState If acState.IsQuiescent Then GoTo Continue Else DoEvents GoTo Wait End If End Sub Quote
Freerefill Posted July 6, 2009 Posted July 6, 2009 There's a way to shut down processes from the Windows command prompt using taskkill, but it's only available on certain versions of Windows. You can find it elsewhere and download it, just do a google search for "taskkill.exe". You could then make it into a one-line batch file and you're done. Hope that helps a bit. ^.^ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.