vba - How to check if hyperlinked file has the correct file path -


i have program prompts user select document file explorer window, can rename want, , show hyperlink in active cell, on click, open linked file. however want restrict files can link path (like s:/folder/folder/folder/filelocation). here code:

strfilename = application.getopenfilename("*.*, files", , , , false) if strfilename = "false"     exit sub 'code responds when user cancelled , not want add file database end if  strshortname = inputbox("what want call link?", "file name", strfilename) 'prompts user insert                                                                                          'the name of file if strshortname = "" exit sub 'attaches entered name document      activesheet.hyperlinks.add anchor:=selection, address:=strfilename, texttodisplay:=strshortname     activecell.offset(1).entirerow.insert                     'the above code creates hyperlink using entered name , connects document                     'that first selected insert database prompt2:     strdate = inputbox("please enter date received file in following format: mm/dd/yyyy .", "date received", strdate)     if strdate = ""         selection.entirerow.delete         exit sub 'code responds when user cancelled , not want add file database     elseif len(strdate) < 12          'this code makes sure date real , inserts in         cells(activecell.row, 8) = strdate 'correct row in corresponding column     else         msgbox ("please enter date in correct format.")  'message box informs user insert correct format         goto prompt2                                             'and restarts prompt attempt     end if  end if   else msgbox ("you cannot add document here.") 'this handles if user enters code column not correspond exit sub  end if 

the solutions have tried follow:

if instr(1, strfilename, "s:/folder/folder/folder/filelocation") = 1 msgbox "this valid location select file from" end if 

and:

    if strfilename "s:/folder/folder/folder/filelocation*"then     msgbox("this valid location seclect file from")     end if 

neither of these work @ all. help.

could try

if instr(1,strfilename,"s:/") >0     msgbox("this valid location seclect file from") end if 

basically if search string ("s:/") in strfilename return >0


Comments