Trying to open Step file in VBA

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. 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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,020
Messages
6,122,709
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top