I am trying to run a VBA script in Autocad and I get the following error: “Automation Error – element not found” Clicking on Debug highlights this line:
Set xlbook = GetObject(“C:75094-LB-06 MX-sv.xlsx”)
I can see that the file is present in the folder.
<code>Public acad As Object
Public acadapp As AcadApplication, AcadDoc As AcadDocument
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public ssnew2 As Object
Public Theatts As Variant
Public Theatts2 As Variant
Public MsgBoxResp As Integer
Private Sub CommandButton1_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlbook = GetObject("C:75094-LB-06MX-SV.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
ro = 2
'declare local variables
Dim dwgName As String
Dim vtag As String
'vtag = "c:7509" & sh.Cells(ro, 5) & ".dwg"
Debug.Print vtag
testflZS
xlbook.Close savechanges:=False
'save the changes in Excel
xlapp.Quit
'quit Excel
Set xlSheet = Nothing
Set xlbook = Nothing
Set axlapp = Nothing
'clean up
ThisDrawing.Save
ThisDrawing.Close
xlapp.DisplayAlerts = True
End Sub
Private Sub CommandButton3_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim ssnew As Object
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
</code>
<code>Public acad As Object
Public acadapp As AcadApplication, AcadDoc As AcadDocument
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public ssnew2 As Object
Public Theatts As Variant
Public Theatts2 As Variant
Public MsgBoxResp As Integer
Private Sub CommandButton1_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlbook = GetObject("C:75094-LB-06MX-SV.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
ro = 2
'declare local variables
Dim dwgName As String
Dim vtag As String
'vtag = "c:7509" & sh.Cells(ro, 5) & ".dwg"
Debug.Print vtag
testflZS
xlbook.Close savechanges:=False
'save the changes in Excel
xlapp.Quit
'quit Excel
Set xlSheet = Nothing
Set xlbook = Nothing
Set axlapp = Nothing
'clean up
ThisDrawing.Save
ThisDrawing.Close
xlapp.DisplayAlerts = True
End Sub
Private Sub CommandButton3_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim ssnew As Object
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
</code>
Public acad As Object
Public acadapp As AcadApplication, AcadDoc As AcadDocument
Public doc As Object
Public ms As Object
Public ss As Object
Public ssnew As Object
Public ssnew2 As Object
Public Theatts As Variant
Public Theatts2 As Variant
Public MsgBoxResp As Integer
Private Sub CommandButton1_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
'Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlbook = GetObject("C:75094-LB-06MX-SV.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
ro = 2
'declare local variables
Dim dwgName As String
Dim vtag As String
'vtag = "c:7509" & sh.Cells(ro, 5) & ".dwg"
Debug.Print vtag
testflZS
xlbook.Close savechanges:=False
'save the changes in Excel
xlapp.Quit
'quit Excel
Set xlSheet = Nothing
Set xlbook = Nothing
Set axlapp = Nothing
'clean up
ThisDrawing.Save
ThisDrawing.Close
xlapp.DisplayAlerts = True
End Sub
Private Sub CommandButton3_Click()
Dim BlkG(0) As Integer
Dim ro As Integer
Dim ssnew As Object
Dim TheBlock(0) As Variant
Dim Pt1(0 To 2) As Double
Dim Pt2(0 To 2) As Double
Dim insertionPnt(0 To 2) As Double
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlbook = GetObject("C:75094-LB-06 MX-sv.xlsx")
Set xlSheet = xlbook.Sheets("04-LB-06 MX")
Set xlapp = xlbook.Parent
xlapp.DisplayAlerts = False
'set reference to workbook
I tried to run the script and I expected it to generate some Autocad drawings.