Porting Excel/Access VBA Macros & ActiveX COM Automation (GetObject / CreateObject) to GstarCAD 2027
Migrate enterprise Excel VBA BOM generators, automated drawing generators, and external VB6/Python COM scripts from AutoCAD.Application to GstarCAD.Application in minutes.
1. 1:1 ActiveX COM Object Model Parity (`GcadApplication`)
Thousands of manufacturing and engineering firms rely on Microsoft Excel VBA workbooks that read engineering parameters from spreadsheet cells and automatically draw 2D assemblies, electrical schematics, or title blocks in CAD via ActiveX COM automation. Because GstarCAD 2027 exposes a complete dual-interface COM Type Library (gcax27enu.tlb) that mirrors AutoCAD's object hierarchy (Application → Documents → ModelSpace / PaperSpace → Layers / Blocks), existing VBA macros migrate with almost zero code changes.
2. ProgID & Late-Binding vs. Early-Binding Reference Table
To convert an Excel VBA macro or standalone VBScript/Python script from AutoCAD to GstarCAD 2027, update the COM Programmatic Identifier (ProgID) as shown below:
| COM Binding Dimension | Legacy AutoCAD VBA / COM | GstarCAD 2027 VBA / COM Equivalent |
|---|---|---|
| Version-Independent ProgID | "AutoCAD.Application" |
"GstarCAD.Application" |
| Version-Specific ProgID (2027) | "AutoCAD.Application.25" |
"GstarCAD.Application.27" |
| In-Process `.DVB` Project Engine | VBAIDE / `VBAMAN` (`ThisDrawing`) |
Native `VBAIDE` / `VBAMAN` (`ThisDrawing` object identical) |
3. Dual-Compatible Excel VBA Macro Pattern (Works on Both GstarCAD & AutoCAD)
By using late binding (`Dim cadApp As Object`) and a fallback `On Error Resume Next` ProgID resolver, your Excel VBA engineering workbooks can drive both GstarCAD 2027 and AutoCAD seamlessly across hybrid enterprise teams:
' Microsoft Excel VBA — Hybrid Connector for GstarCAD 2027 & Legacy AutoCAD
Sub PushExcelScheduleToGstarCAD()
Dim cadApp As Object
Dim cadDoc As Object
Dim ptIns(0 To 2) As Double
On Error Resume Next
' 1. Try attaching to running GstarCAD 2027 instance first
Set cadApp = GetObject(, "GstarCAD.Application")
If cadApp Is Nothing Then
Set cadApp = CreateObject("GstarCAD.Application")
End If
' 2. Fallback for external subcontractors still on AutoCAD
If cadApp Is Nothing Then
Set cadApp = GetObject(, "AutoCAD.Application")
End If
On Error GoTo 0
If cadApp Is Nothing Then
MsgBox "Neither GstarCAD nor AutoCAD is installed on this workstation.", vbCritical
Exit Sub
End If
cadApp.Visible = True
Set cadDoc = cadApp.ActiveDocument
ptIns(0) = 100#: ptIns(1) = 250#: ptIns(2) = 0#
' Identical COM method call across both platforms
cadDoc.ModelSpace.AddMText ptIns, 120#, "GENERATED VIA EXCEL COM AUTOMATION"
cadDoc.Regen 1 ' acAllViewports
End Sub
4. Automating `.DVB` Startup Loading & 64-Bit API PtrSafe Declarations
When migrating legacy AutoCAD VBA macros originally authored in 32-bit environments (AutoCAD 2004–2013) into 64-bit GstarCAD 2027 (which ships with the Microsoft Visual Basic for Applications 7.1 x64 runtime), any Windows Win32 API `Declare Function` calls inside your `.dvb` modules must include the `PtrSafe` keyword and use `LongPtr` for window handles (`HWND`) and memory pointers:
' Conditional VBA 7.1 64-bit / 32-bit Win32 API Declaration inside GstarCAD .DVB
#If VBA7 Then
Private Declare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongLong
Private Declare PtrSafe Function FindWindowA Lib "user32" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
Private Declare Function GetTickCount Lib "kernel32" () As Long
#End If
Enterprise Auto-Loading via `gcaddoc.lsp`: Rather than instructing users to run `VBALOAD` manually every morning, deploy your `.dvb` project to a read-only network share and invoke `-VBARUN` transparently from Ribbon buttons or AutoLISP command wrappers:
;; Inside gcaddoc.lsp: Demand-load corporate DVB and expose native command C:BOMSYNC
(defun C:BOMSYNC ( / dvbPath)
(setq dvbPath (findfile "CorpTools_2027.dvb"))
(if dvbPath
(progn
(vl-vbaload dvbPath)
(vl-vbarun "ModERP.SyncActiveTitleBlockToSAP")
)
(princ "
[ERROR] CorpTools_2027.dvb not found in Support File Search Path.")
)
(princ)
)
Validate This Workflow in GstarCAD 2027
Engineered by Suzhou Gstarsoft Co., Ltd. (SSE: 688657), GstarCAD 2027 delivers 100% native AC1032 DWG binary fidelity, perpetual licensing sovereignty, and zero-day AutoCAD command parity.