Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
With VBA i need to open a drawing part from user form.
I have all the paths and part numbers correct but can`t seem to hyperlink to the drawing part. It just goes to the message rather than open the drawing.
I have all the paths and part numbers correct but can`t seem to hyperlink to the drawing part. It just goes to the message rather than open the drawing.
VBA Code:
Private Sub Open_Part_Click()
Dim SourcePath As String
Dim SubPath As String
Dim SLDPRT As String
Dim MyPath As String
Dim SLDPRTFile As String
Dim SLDPRTName As String
Dim cmbdata
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 = (cmbdata(0))
strPath = SourcePath & "\" & SubPath
ElseIf ActiveSheet.Name = "DrNo Dic" Then
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
SLDPRTFile = OpenDrawing.Value
If ActiveSheet.Name = "Frost Drains" Then
SLDRTFile = SourcePath & "\" & SubPath & "\" & SLDPRTFile & ".SLDPRT"
Else
SLDRTFile = SourcePath & "\" & SubPath & "\" & Int(cmbdata(0)) & "\" & SLDPRTFile & ".SLDPRT"
End If
SLDPRTName = OpenDrawing.Value
On Error Resume Next
If PartFile_Exists(SLDPRTName) Then
ActiveWorkbook.FollowHyperlink SLDPRTName
Else
MsgBox "There is no Workshop Drawing in Folder! Otherwise Specify what DrNo you Require"
Exit Sub
End If
End Sub
Private Function PartFile_Exists(ByVal SLDPRTFile As String, _
Optional Directory As Boolean) As Boolean
On Error Resume Next
If SLDPRTFile <> "" Then
If IsMissing(Directory) Or Directory = False Then
PartFile_Exists = (Dir$(SLDPRTFile) <> "")
Else
PathFile_Exists = (Dir$(SLDPRTFile, vbDirectory) <> "")
End If
End If
End Function