VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error using VBA in Excel to open Civil 3D 2011 with a borrowed license

3 REPLIES 3
Reply
Message 1 of 4
Private2at
787 Views, 3 Replies

Error using VBA in Excel to open Civil 3D 2011 with a borrowed license

I have been searching for a solution to this problem for a couple of days and coming up empty so far.  I have a bit of VBA code in in excel that works just fine in the office, but fails and returns errors when I am working with a borrowed license.  I am not a programmer and this is my first foray into VBA.  I have picked up most by hunting around the net and reading other code I have found.  If someone knows a way to make this work with a borrowed license as well as a non borrowed license that would be much appreciated. 

 

My goal with this portion of the Code is simply to open a standard drawing from a specified location, or use the existing standard drawing if it is already open.

 

the snippet of the code that I am using and works in the office is as follows:

 

Sub Export_to_AutoCAD()
     Dim Acad As AcadApplication

 

     On Error Resume Next
     Set Acad = GetObject(, "AutoCAD.Application")
     On Error GoTo 0
     If Acad Is Nothing Then
         Set Acad = New AcadApplication
     End If

     Acad.Visible = True

 

     'Open specific Standard Drawing in order to fill in table with data from this spreadsheet
     Dim NewFile As AcadDocument
     Dim DwgFilePath As String
     Dim DwgName As String
     Dim DwgLocation As String
     Dim DwgReadOnly As Boolean

 

     Worksheets("Setup").Activate
     DwgFilePath = Range("B2")
     DwgName = Range("B4")
     DwgLocation = DwgFilePath & "\" & DwgName
     DwgReadOnly = True

 

     On Error Resume Next
     Set NewFile = Acad.Documents.Open(DwgLocation, DwgReadOnly)
     On Error GoTo 0
     If NewFile Is Nothing Then
Errormessage:
        If NewFile = "False" Then End
            MsgBox ("Could not find the required spreadsheet.  Ensure the path and filename are correct" & vbCr & DwgFilePath & DwgName & vbCr & "Rename or relocate the required drawing file as needed.")
        End
        Acad.Quit
        Acad = Nothing
        NewFile = Nothing
     End If

3 REPLIES 3
Message 2 of 4
TravisNave
in reply to: Private2at

Borrowed licenses are user-specific.  It may be possible that your script is launching your product as a different user or user profile and not seeing the borrowed license. 



Travis Nave Send TravisNave a Private Message                                             Need help in your post? Mention me with @TravisNave



My Expert Contributions to the
Autodesk Forums:
FLEXnet License Admin | MSI Cleanup Utility | .NET Framework Cleanup Tool | IPv6 NLM Fix | adskflex.opt Options File | Combine .LIC Files
Message 3 of 4
Private2at
in reply to: Private2at

hrmm maybe.  One thing I do notice though is that AutoCAD does actually launch.  if I then step through the script, I get the error at the stage if opens the existing drawing (and always get it there on subsequent stepping through of the code).  When I flip over to AutoCAD I can see the drawing drawing open too.  But due to the error, it will not step through the rest of the code (not included)

Message 4 of 4

Without seeing what type of error you are getting or what happens next in any form it's hard to tell, but are you giving autocad time to finish opening the drawing?

 

Try throwing in a pause in the program to let autocad open the drawing. Something like this.

 

    Dim PauseTime, Start
    
    PauseTime = 10    ' Set duration.
    Start = Timer    ' Set start time.
    
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop

 



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 10 Enterprise 64bit
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2021

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost