Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
Please help trying to open Step file with VBA. The code below won`t work says error 438??
VBA Code:
Set swApp = Application.SldWorks
VBA Code:
Private Sub Open_DrNo_Step_Click()
Dim SourcePath As String
Dim SubPath As String
Dim Step As String
Dim MyPath As String
Dim StepName As String
Dim StepFile As String
Dim swApp As SldWorks.SldWorks
Dim Doc As SldWorks.ModelDoc2
Dim swFilter As String
Dim swModel As ModelDoc2
Dim swDocSpecification As DocumentSpecification
Dim Cmbdata
Dim FileError As Long
Dim FileWarning As Long
Set swApp = Application.SldWorks
swApp.Visible = True
Cmbdata = Split(Me.OpenDrawing.Value, "-")
Cmbdata(0) = Replace(Cmbdata(0), "-", "")
If ActiveSheet.Name = "Frost Drains" Then
SourcePath = "\\DF-AZ-FILE01\Company\R&D\Drawing Nos\Frost Grates"
SubPath = Me.OpenDrawing.Value
GoTo OpenStep
Else: SourcePath = "S:\R&D\Drawing Nos"
End If
If Val(Cmbdata(0)) >= 10001 And Val(Cmbdata(0)) <= 10050 Then
SubPath = "10001-10050"
ElseIf Val(Cmbdata(0)) >= 10051 And Val(Cmbdata(0)) <= 10100 Then
SubPath = "10051-10100"
ElseIf Val(Cmbdata(0)) >= 10101 And Val(Cmbdata(0)) <= 10150 Then
SubPath = "10101-10150"
ElseIf Val(Cmbdata(0)) >= 10151 And Val(Cmbdata(0)) <= 10200 Then
SubPath = "10151-10200"
End If
OpenStep:
Step = Me.OpenDrawing.Value
StepFile = SourcePath & "\" & SubPath & "\" & Step & ".Step"
Set Doc = swApp.OpenDoc6(StepFile, swDocStep, swOpenDocOptions_Silent, "", FileError, FileWarning)
End Sub