Message 1 of 4

Not applicable
06-13-2018
02:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all. I having autocad project where is 1 dynamic block which I'm trying to change from excel. Here is vba script which I'm using to change block:
Dim dybprop As Variant, i As Integer Dim bobj As AcadEntity For Each bobj In ACADApp.ModelSpace If bobj.ObjectName = "AcDbBlockReference" Then If bobj.IsDynamicBlock Then If bobj.EffectiveName = "AdjBlock" Then dybprop = bobj.GetDynamicBlockProperties For i = LBound(dybprop) To UBound(dybprop) If dybprop(i).PropertyName = "Distance1" Then dybprop(i).Value = 50.75 Acad.Application.Update End If Next i End If End If End If Next
When I'm running it in AutoCAD VBA it works excellent. Than I'm creating Excel VBA project and copying this code. Before running it I creating connection to existing AutoCad project like this:
On Error Resume Next Dim ACADApp As AcadApplication Dim a As Object Set a = GetObject(, "AutoCAD.Application") If a Is Nothing Then Set a = CreateObject("AutoCAD.Application") If a Is Nothing Then MsgBox "AutoCAD must be running before performing this action.", vbCritical Exit Sub End If End If Set ACADApp = a Set ACADApp.ActiveDocument = ACADApp.Documents.Open("c:\KIRILL\Programming\Drawing1_VBATest.dwg")
When I'm running it from Excel VBA - AutoCAD project appears but nothing change. Honestly I don't have any idea why in Excel VBA it doesn't works while in AutoCAD it work. May be somebody had this problem before? Thanks in advance.
P.S. Full Excel VBA code:
Sub Button9_Click() On Error Resume Next Dim ACADApp As AcadApplication Dim a As Object Set a = GetObject(, "AutoCAD.Application") If a Is Nothing Then Set a = CreateObject("AutoCAD.Application") If a Is Nothing Then MsgBox "AutoCAD must be running before performing this action.", vbCritical Exit Sub End If End If Set ACADApp = a Set ACADApp.ActiveDocument = ACADApp.Documents.Open("c:\KIRILL\Programming\Drawing1_VBATest.dwg") Dim dybprop As Variant, i As Integer Dim bobj As AcadEntity For Each bobj In ACADApp.ModelSpace If bobj.ObjectName = "AcDbBlockReference" Then If bobj.IsDynamicBlock Then If bobj.EffectiveName = "AdjBlock" Then dybprop = bobj.GetDynamicBlockProperties For i = LBound(dybprop) To UBound(dybprop) If dybprop(i).PropertyName = "Distance1" Then dybprop(i).Value = 50.75 Acad.Application.Update End If Next i End If End If End If Next End Sub
Solved! Go to Solution.