I have the following code. My plan is to check whether a drawing is in a folder, if not then go to other folder to open.
However, it does not work
I believe the error is from line 38
Any suggestion?
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SelectionMgr
Dim selComp As Component2
Dim sPath As String
Dim sPath1 As String
Dim sPathX As String
Dim sPath2 As String
Dim i As Integer
Dim iCount As Integer
Dim longstatus As Long
Dim longwarnings As Long
Dim Part As Object
Sub Main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
iCount = swSelMgr.GetSelectedObjectCount2(-1)
For i = 0 To iCount - 1
Set selComp = swSelMgr.GetSelectedObjectsComponent4(i + 1, -1)
Debug.Print selComp.Name2
sPath = Strings.Mid(selComp.GetPathName, InStrRev(selComp.GetPathName, "\") + 1)
sPath = Left(sPath, InStrRev(sPath, ".") - 1)
sPath1 = "C:\ET-VAULT\Automation\Projects\PRJ-0532\CAD Files\" & sPath & ".SLDDRW"
sPathX = "C:\ET-VAULT\Automation\Projects\PRJ-0497\CAD Files\" & sPath & ".SLDDRW"
sPath2 = "C:\Users\saikit.wu\Desktop\VENDOR PRINT\" & sPath & ".PDF"
'Set Part = swApp.OpenDoc6(sPath, 3, 0, sPath1, longstatus, longwarnings)
If IsNull(swApp.OpenDoc6(sPath1, 3, 0, "", longstatus, longwarnings)) Then
Set Part = swApp.OpenDoc6(sPathX, 3, 0, "", longstatus, longwarnings)
Else
Set Part = swApp.OpenDoc6(sPath1, 3, 0, "", longstatus, longwarnings)
End If
Set Part = swApp.ActiveDoc
longstatus = Part.SaveAs3(sPath2, 0, 0)
'Part.PrintDirect
'swApp.CloseDoc Part.GetTitle
Next i
End Sub