By Daniel Du
Issue
Why do I get an error when I try to set the ConfigName of a Layout?
Solution
The usual reason for this error is that you are not calling 'RefreshPlotDeviceInfo' before assigning a 'ConfigName'.
Here is an example of some VBA code that does work:
Sub Test()
Dim Layouts As AcadLayouts
Dim Layout As AcadLayout
' Get the files preferences object
Set Layouts = ThisDrawing.Layouts
' Change plotter configuration file
Layouts("Model").RefreshPlotDeviceInfo
Layouts("Model").ConfigName = "PrinterName"
ThisDrawing.Plot.PlotToDevice
End Sub
If you comment out the line 'Layout("Model").RefreshPlotDeviceInfo', the routine will work sometimes, but not always.
Please note that you will still generate an error if you try to set a ConfigName that AutoCAD cannot find.