VBA Automation Fails to Connect with Civil 3D 2023 / AutoCAD 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm facing a persistent issue when trying to automate the creation of longitudinal profiles in Civil 3D 2023 (and AutoCAD 2023) from an Excel VBA macro.
The goal is to read data from Excel and draw elements such as terrain lines, pipes, manholes, dimensions, and text directly into the model space. However, I cannot establish a reliable connection between Excel and Civil 3D/AutoCAD using GetObject or CreateObject, despite having a valid license and a clean installation.
What I've Tried:
Basic connection with GetObject:
vba
Set acadApp = GetObject(, "AutoCAD.Application")
Sometimes works, but most of the time it fails without a clear reason.
Using the specific Civil 3D name:
vba
Set acadApp = GetObject(, "Civil3D.Application")
Never works, even when Civil 3D is open.
Running accoreconsole.exe /regserver:
- Executed as Administrator.
- Full repair of Civil 3D 2023 via Autodesk Desktop App.
- The COM registration seems not to be restored correctly.
VBA References:
Added "Autodesk Civil 3D 2023 Type Library".
The problem persists even with the reference enabled.
Alternative: .SCR scripts:
They work, but this is not the ideal solution as I need an interactive workflow from Excel.
Running as Administrator, macros enabled, only one AutoCAD process open, etc.
Symptoms:
The code stops at Set acadDoc = acadApp.ActiveDocument with the error "Object variable or With block variable not set".
Sometimes, acadApp is Nothing even when Civil 3D is open.
The system does not recognize Civil3D.Application in the COM registry.
No license or installation errors.
Environment:
Operating System: Windows 10/11 (64-bit)
Applications: Civil 3D 2023 (valid license), AutoCAD 2023
Automation Tool: Excel 2019/365 with VBA
Goal: Draw longitudinal profiles from structured data.
Question:
Has anyone successfully established a stable and reliable connection between VBA in Excel and Civil 3D 2023?
Is there a definitive solution for GetObject to work consistently?
Is this a known issue in version 2023?
I would greatly appreciate any guidance, working example, or viable alternative.
Best regards.