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
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.
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)
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