Trying to open a part drawing

Eric Penfold

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

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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

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