My Dir is not working

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
When i change the sheet i need to go to a different path. But the Dir does not work??
This line shows ""
VBA Code:
strFolder = Dir(strPath, vbDirectory)


VBA Code:
Private Sub OpenFolder_Click()

    Dim SourcePath As String
    Dim SubPath      As String
    Dim strFolder     As String
    Dim strPath        As String
    Dim PDFFName As String
    Dim Answer        As VbMsgBoxResult
    Dim cmbdata

        cmbdata = Split(Me.OpenDrawing.Value, "-")
        cmbdata(0) = Replace(cmbdata(0), "-", "")
        
        If ActiveSheet.Name = "Frost Drains" Then
        SourcePath = "S:\R&D\Drawing Nos\Frost Grates"
        GoTo Path
        
        ElseIf ActiveSheet.Name = "DrNo Dic" Then
        SourcePath = "S:\R&D\Drawing Nos"
        GoTo Path
        
Path:
    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
        
    strPath = SourcePath & "\" & SubPath & "\" & Int(cmbdata(0))
    strFolder = Dir(strPath, vbDirectory)
    
            On Error Resume Next
             If strFolder = strFolder Then
             ActiveWorkbook.FollowHyperlink Address:=strPath, NewWindow:=True
             End If
             
              If strFolder = vbNullString Then
                     Answer = MsgBox("Folder - Path does not exist. Would you like to create it?", vbYesNo, "Create Folder - Path")
                If Answer = vbNo Then
                    Exit Sub
                        ElseIf Answer = vbYes Then
                            VBA.FileSystem.MkDir (strPath)
                      End If
                End If
        End If
      
End Sub
 
If the code stops then it has completed, so I don't know what you mean about resetting it? Sorry i was getting confused

Your code also tries to follow a link to the folder before checking if it exists, which seems a little odd to me. The checking folder exist is now in the correct order
It`s still the
VBA Code:
strFolder = Dir(strPath, vbDirectory)
which shows ""
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I can't think of any other reason than that the folder path doesn't exist.
 
Upvote 0
Solution
Just to check: how did you do that? The full path is not included your code, it's calculated at runtime.
 
Upvote 0
Sorry me being an an idiot the sub path was not right all working fine now.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,150
Members
453,021
Latest member
Justyna P

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