search and open main folder & subfolder and file by inputbox

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i know what i'm looking for is complicated in my mind if is there way do that by inputbox
show the inputbox and write the main folder if is not exist then message show " not exist if is existed then show me two choices if i choose no then exit sub if ok then show another inputbox to fill subfolder name if is not exist then message show " not exist if is existed then show me two choices if i choose no then exit sub if ok then show another inputbox to fill name's file if is not exist then message show " not exist if is existed then show me two choices if i choose no then exit sub if ok then open it
thanks advance
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Why not just use FilePicker and browse the dialog box to see if the file you want is there.
VBA Code:
Sub t()
Dim fd As FileDialog, wb As Workbook, fName As String
Set fd = Application.FileDialog(msoFileDialogFilePicker).Show
fName = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
Set wb = Workbooks.Open(fName)
'Code to do stuff
wb.Close
End Sub
 
Upvote 0
hi, JLGWHIZ thanks for your advice but by inputbox saves time if i write the directory and search it brings directly but if i use by filepicker it takes more time to reach the specific folder i have to move from folder to another to reach the aim of folder and not only open exel i would open any file pdf,avi,jpg ...etc and when i add msgbox it helps me if the file is not existed it has to change the name folder or file as what i explained
by the way your code gives me error mismatch about word "show"
thanks
 
Upvote 0
VBA Code:
Sub t()
Dim fPath, ans As Variant
Retry:
fPath = InputBox("Enter Path to Folder", "Directory Path")
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
    If Dir(fPath, vbDirectory) <> "" Then
        MsgBox "Folder Exists"
    Else
        ans = MsgBox("Folder does not exist, Do you want to continue?", vbYesNo + vbQuestion, "Continue?")
            If ans = vbYes Then
                GoTo Retry:
            Else
                Exit Sub
            End If
    End If
End Sub

For the previous code the Show should have been on a separate line as fd.Show, My error.
 
Upvote 0
sorry about delaying to answer you i have some notices when i press cancel it gives me folder exist it supposes only exit and when it gives me message folder is existed then move another inputbox to write names of subfolder if existed then move another inputbox to write the file if is existed gives me message two choices if press ok open the file if no exit i would appreciate if you can achieve this
thanks for your interesting
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,666
Members
449,114
Latest member
aides

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