AutoCAD Object Instantiation in VBA

AutoCAD ActiveX

 
AutoCAD Object Instantiation in VBA
 
 
 

64-bit operating systems can execute both 32-bit and 64-bit applications, but they cannot mix these types within a process. For example, you cannot load 32-bit DLLs into a 64-bit process, or vice versa. All executable components (EXE and DLL files) that are loaded into a process must match the binary type of the process. In-process components for your 64-bit applications should be ported to 64-bit processes as much as possible.

One error could occur when attempting to create a new object. VB’s New keyword will attempt to load 64-bit AutoCAD COM DLLs. Since VBA is a 32-bit application, it cannot load 64-bit DLLs. For example, code such as

Dim color As AcadAcCmColor
Set color = New AcadAcCmColor

or

Dim color As New AcadAcCmColor
color.SomeMethod()

needs to be modified and ported to

Dim color As AcadAcCmColor
Set color = AcadApplication.GetInterfaceObject(“Autocad.AcCmColor.17”). 

The above issue should be resolved using AcadApplication.GetInterfaceObject(“ProgIdOfAcAnyObject”) for any object that is derived from IDispatch. Classes derived from IUnknown (e.g. AcSmSheetSet, AcSmSheetMgr etc) are not expected to have a 64-Bit VBA migration. It is recommended that you port such processes to VB .Net.