Directory Change

dcoledc

Active Member
Joined
May 6, 2010
Messages
403
I have this code that I have been using to allow the user to open a workbook within a specific folder:

Code:
10: Dim sFullPath As String
    
    ChDir ThisWorkbook.Path
    ChDir ".\..\" & "Patient Files"
    sFullPath = Application.GetOpenFilename("Excel Files (*.xl*)," & _
    "*.xl*", 1, "Select Patient File", "Open", False)

I am looking to add an If/Then statement right after this code that tests to see if the file the user tries to open is from another directoy and if so prevent them.

Is there a way to do that?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Got it!

10: Dim sFullPath As String
Dim Force As String
ChDir ThisWorkbook.Path
ChDir ".\..\" & "Patient Files"
Force = CurDir
sFullPath = Application.GetOpenFilename("Excel Files (*.xl*)," & _
"*.xl*", 1, "Select Patient File", "Open", False)
If Force <> CurDir Then
MsgBox "Invalid selection.", vbOKOnly + vbCritical, "Reports to Go..."
GoTo 10
End If
 
Upvote 0
Not quite. Strangely, if while in the fiel dialog, I go to the side and choose something from say "My Documents", my code doesn't work. I did a quick msgbox to see what the dir were and sure enough they were the same.

Anyone know why the directories would be the same even though I changed locations?

or does anyone have a solution?
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,823
Members
452,946
Latest member
JoseDavid

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