Results 1 to 6 of 6

Thread: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

  1. #1
    Member
    Join Date
    2007-04
    Posts
    16
    Login to Give a bone
    0

    Question Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    I'm trying to start ACAD from a Excel using VBA - the code works fine-if ACAD is already running. I'm trying to make it a wee bit more user friendly and have the Excel VBA open ACAD if it isn't already running.

    excel_vba_references.PNG

    The references have been correctly set (I think)

    vba_code_autocad_excel.PNG

    The code comes from somewhere - too many sources to recall the exact location.

    vba_code_error_429.PNG

    The error message I receive.

    I'm running 64 Bit AutoCAD and 64 bit Office 2010.

    Sandbox mode is '2'

  2. #2
    Member
    Join Date
    2007-04
    Posts
    16
    Login to Give a bone
    0

    Default Re: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    Going on three months and not one reply - no luck on my end either.

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,409
    Login to Give a bone
    0

    Default Re: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    Have you tried setting a breakpoint and running in debug mode to see what line the error occurs at?
    C:> ED WORKING....


    LinkedIn

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    Quote Originally Posted by Mike_S_Jones View Post
    Going on three months and not one reply - no luck on my end either.
    create .XlSM file then add this code in module named
    modTestAcad, but before run this module select single cell before
    Code:
    Option Explicit
    ' require references to:
    
    'Windows Script Host Object model
    
    'AutoCAD 20XX Type Library
    
    'AutoCAD Focus Control for VBA Type Library
    
    'in the Tools -> Options -> General -> Error Trapping box -> Check "Break on Unhandled Errors"
    
    Function acadVerNum() As String
    Dim verNum As String
    
    verNum = "HKEY_CLASSES_ROOT\AutoCAD.Drawing\CurVer\"
    Dim wsh As Object
    
      On Error GoTo ErrorHandler
      'access Windows scripting
      Set wsh = CreateObject("WScript.Shell")
      'read key from registry
      Dim resKey As String
      resKey = wsh.RegRead(verNum)
      
     acadVerNum = Right(resKey, 2)
      Exit Function
      
    ErrorHandler:
      'key was not found
     acadVerNum = ""
        
    End Function
    
    Public Sub testOpenAutoCAD()
    
    Dim acad As AutoCAD.AcadApplication
    Dim appNum As String
    On Error GoTo ErrorHandler
    appNum = acadVerNum
    If appNum = "" Then
    Exit Sub
    End If
    On Error Resume Next
    Set acad = GetObject(, "Autocad.Application." & appNum)
    If Err.Number = 429 Then
    Err.Clear
    
    On Error GoTo 0
    Set acad = CreateObject("Autocad.Application." & appNum)
    If Err Then
    Exit Sub
    End If
    End If
    
    acad.WindowState = acMax
    
    Dim adoc As AutoCAD.AcadDocument
    Set adoc = acad.ActiveDocument
    
    Dim selRng As Range
    Set selRng = Selection
    selRng.Value2 = "Tested on: " & adoc.Name
    
    Dim aspace As AutoCAD.AcadBlock
    
    Set aspace = adoc.ActiveLayout.Block
    
    Dim p1(0 To 2) As Double
    Dim p2(0 To 2) As Double
    Dim lw As Double
    Dim clr As Integer
    
    
    p1(0) = 0#: p1(1) = 0#: p1(2) = 0#
    p2(0) = 100#: p2(1) = 100#: p2(2) = 0#
    
    lw = acLnWt060
    clr = "0"
    Dim oLine As AcadLine
    Set oLine = aspace.AddLine(p1, p2)
    oLine.Lineweight = lw
    oLine.Color = acMagenta
    
    adoc.SetVariable "lwdisplay", 1
    adoc.SetVariable "ltscale", 0.25
    ZoomExtents
    
    Set aspace = Nothing
    Set adoc = Nothing
    Set acad = Nothing
    
    
    MsgBox "Pokey"
    
    ErrorHandler:
      If Err.Number <> 0 Then
      MsgBox Err.Description
      End If
    End Sub

  5. #5
    Member
    Join Date
    2007-04
    Posts
    16
    Login to Give a bone
    0

    Default Re: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    @Fixo

    Your code worked great - thanks for posting!

    Very belated reply, but side projects at work always seem to get shunted to the side.

    Thanks again.

    Mike

  6. #6
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: Excel 2010 - Autocad 2012 - Win 7 64 bit - Error 429 running Excel VBA code

    Hi Mike,
    I'm ery happy if this helps in your work
    Cheers,

Similar Threads

  1. Replies: 1
    Last Post: 2012-08-08, 05:50 PM
  2. 2012: Excel to Autocad 2012
    By bmccoy in forum AutoCAD Customization
    Replies: 0
    Last Post: 2011-09-23, 07:33 PM
  3. AutoCad 2010 ctb to excel?
    By dszuflita in forum Software
    Replies: 1
    Last Post: 2011-06-28, 08:06 PM
  4. Replies: 1
    Last Post: 2009-04-29, 11:03 AM
  5. Problem Running Excel From AutoCAD Shell Command
    By CADdancer in forum AutoLISP
    Replies: 5
    Last Post: 2006-02-10, 02:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •