title: How to open a windows explorer to select a file without hard coding the full location of the file, just the folder using vbs?
body: <p>I am trying to find a way to open a windows explorer window to select a file. I want to open the folder that the file will be in and then select the file manually. It will be a different file everyday so I don't want to hard code the file name just the location. I've found a lot of examples of how to open the file, but none that would allow me to open the folder and then select the file that I want to open. I'm doing this in VBS.</p>
  
  <p>EDIT: Here is the code that I'm working on</p>
  
  <pre><code>Option Explicit
  dim filename
  filename = ChooseFile()
  msgBox("File Name is: " &amp; filename)
  
  Function ChooseFile()
  Dim ListCameras(20)
  Dim objExcel
  Dim excelPath
  Dim worksheetCount
  Dim counter
  Dim currentWorkSheet
  Dim usedColumnsCount
  Dim usedRowsCount
  Dim row
  Dim column
  Dim top
  Dim left
  Dim Cells
  Dim curCol
  Dim curRow
  Dim word
  dim Result
  dim x
  dim CellValue
  REM where is the Excel file located?
  dim objFS : set objFS = CreateObject("Scripting.FileSystemObject")
  dim objShell : set objShell = CreateObject("Wscript.Shell")
  dim strPath : strPath = "I:\DVR\Reports\2014\"
  if 1 = Wscript.Arguments.Count then
  strPath = Wscript.Arguments(0)
  if objFS.FileExists(strPath) then
      strPath = objFS.GetParentFolderName(strPath)
      if objFS.FolderExists(strPath) then
          dim strCmd : strCmd = explorer.exe /e &amp; strPath
          objShell.run strCmd
      else
      WScript.Echo "No", strPath
      end if
  end if
  end if
  excelPath = strPath '"I:\DVR\Reports\2014\" &amp; DatePart("m", Now()) &amp; "-" &amp; DatePart("yyyy", Now()) &amp; "\DVR Daily " &amp; DatePart("m", Now()) &amp; "-" &amp; DatePart("d",      Now())-1 &amp; "-" &amp; DatePart("yyyy", Now()) &amp; ".xls"
  WScript.Echo "Reading Data from " &amp; excelPath
  REM Create an invisible version of Excel
  Set objExcel = CreateObject("Excel.Application")
  objExcel.DisplayAlerts = 0  REM don't display any messages about documents needing to   be converted from  old Excel file formats
  objExcel.Workbooks.open excelPath, false, true  'REM open (path,  confirmconversions, readonly)
  REM How many worksheets are in this Excel documents
  workSheetCount = objExcel.Worksheets.Count
  For counter = 1 to workSheetCount   'REM Loop through each worksheet
  WScript.Echo "Reading data from worksheet " &amp; counter &amp; vbCRLF
  Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
  usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
  usedRowsCount = currentWorkSheet.UsedRange.Rows.Count
  top = currentWorksheet.UsedRange.Row
  left = currentWorksheet.UsedRange.Column
  Set Cells = currentWorksheet.Cells  
  For row = 1 to (usedRowsCount-1)    'REM Loop through each row in the worksheet 
      For column = 0 to usedColumnsCount-1    'REM Loop through each column in the worksheet          
          curRow = row+top    'REM only look at rows that are in the  "used" range        
          curCol = column+left    'REM only look at columns that are in the "used" range      
          word = Cells(curRow,curCol).Value   'REM get the value/word  that is in the cell 
          select case column
          case 8
              ListCameras(row) = cells(curRow,curCol) 'add the value of the cell to the list of cameras
          end select
      Next
  Next
  for x = 0 to ubound(ListCameras)
      msgBox(ListCameras(x))
  next
  Result = msgbox("Sheet " &amp; counter &amp; " is done being read." &amp; vbCrLf &amp; "Continue?",vbYesNo)
  if result = vbNo then
      Wscript.quit
  else
      for row = 1 to (usedRowsCount-1) 'loop through the rows
          for column = 0 to usedColumnsCount-1 'loop through the columns
              curRow = row+top
              curCol = column+left
              select case column
              case 8  'switching the current camera for the next one in line
              CellValue = cells(curRow,curCol-8).value
                  if cells(curRow,curCol - 7).value =  cells(curRow,curCol).value then    'check to see if we've reached the end of the camera list
                  cells(curRow,curCol).value = "1"    'start over at the begining
                  else
                      if isNumeric(cells(curRow,curCol).value) then   'check if the value in the camera column is a number
                          cells(curRow,curCol).value = cells(curRow,curCol).value + 1
                      else                         'if its not a number, then it's from one of the FBlueIris DVR's and is named differently
                          dim CameraList : CameraList =  ReturnCameraList(Trim(Right(mid(CellValue,1,4),2)))  'gets the list of cameras based on the branch number
                          dim count : count = 0
                          dim match : match = false
                          dim camera
                          for each camera in CameraList    'loop through the camera list
                              if camera =  cells(curRow,curCol).value then    'check if the current camera is in the list (it should be)
                                  if count =  UBound(CameraList) then 'check count is equal to the number of cameras in the list
                                      count = 0       'restart the count
                                  else
                                      count = count + 1   'add one to move to the next camera in the list
                                  end if
                                  match = True    'if  the camera in the cell is in the list then this should be true
                                  exit for    'exit the loop so that the count does not continue to go up
                              end if
                              count = count + 1   'count goes up so that it will be the next camera in the list
                          next
                          if match = True then
                              cells(curRow,curCol).value = CameraList(count)  'when match is true input the next camera into the cell
                          else
                              cells(curRow,curCol).value = "No camera"    'if not true then enter in "No Camera" so that we will know there is a problem and can find it
                          end if
                      end if
                  end if
              end select
          next
      next
      objExcel.Workbooks(1).SaveAs "I:\DVR\Reports\2014\" &amp; DatePart("m", Now())  &amp; "-" &amp; DatePart("yyyy", Now()) &amp; "\DVR Daily " &amp; DatePart("m", Now()) &amp; "-" &amp;  DatePart("d", Now()) &amp; "-" &amp; DatePart("yyyy", Now()) &amp; ".xls"
      objExcel.Workbooks("DVR Daily " &amp; DatePart("m", Now()) &amp; "-" &amp;  DatePart("d", Now()) &amp; "-" &amp; DatePart("yyyy", Now()) &amp; ".xls").Close True
  end if
  Set currentWorkSheet = Nothing  REM We are done with the current worksheet, release  the memory
  Result = msgbox("Sheet " &amp; counter &amp; " is done being saved." &amp; vbCrLf &amp; "Continue?",vbYesNo)
  if Result = vbNo then
      Wscript.quit
  else 
      exit for
  end if
  Next
  objExcel.Workbooks(1).Close True
  objExcel.Quit
  Set currentWorkSheet = Nothing
  Set objExcel = Nothing  REM We are done with the Excel object, release it from   memory
  End Function
  
  Function ReturnCameraList(branch)
  dim tempArray()
  Select Case branch
      Case 2 'Branch 2
          redim tempArray(10)
          tempArray(0) = "02lobby"
          tempArray(1) = "02tlr1"
          tempArray(2) = "02tlr2"
          tempArray(3) = "02tlr3"
          tempArray(4) = "02tlr4"
          tempArray(5) = "02tlr5"
          tempArray(6) = "02tlr6"
          tempArray(7) = "02VLT"
          tempArray(8) = "02vltdr"
          tempArray(9) = "02bkdr"
          tempArray(10) = "02atm"
          ReturnCameraList = tempArray
      Case 4 'Branch 4
          redim tempArray(9)
          tempArray(0) = "04lobby"
          tempArray(1) = "04frtdoor"
          tempArray(2) = "04loan"
          tempArray(3) = "04bdoor"
          tempArray(4) = "04vlt"
          tempArray(5) = "04tlr1"
          tempArray(6) = "04tlr2"
          tempArray(7) = "04tlr3"
          tempArray(8) = "04tlr4"
          tempArray(9) = "04atm"
          ReturnCameraList = tempArray
      Case 5 'Branch 5
          redim tempArray(16)
          tempArray(0) = "05_Data_Ctr"
          tempArray(1) = "05_Vlt_Dr"
          tempArray(2) = "05_Tlr_Sup"
          tempArray(3) = "05_Frt_Dr"
          tempArray(4) = "05_ATM_Rm"
          tempArray(5) = "05_Tlr_3-4"
          tempArray(6) = "05_Drv_up"
          tempArray(7) = "05_Tlr_7-8"
          tempArray(8) = "05_Back_Dr"
          tempArray(9) = "05_ATM"
          tempArray(10) = "05_Vlt_Rm"
          tempArray(11) = "05_Tlr_1-2"
          tempArray(12) = "05_Coin_Ctr"
          tempArray(13) = "05_Tlr_5-6"
          tempArray(14) = "05_Frt_Lby"
          tempArray(15) = "05_Emply_Ent"
          tempArray(16) = "05_Frt_Strs"
          tempArray(16) = "Emp_Lot"
          ReturnCameraList = tempArray
      Case 13 'Branch 13
          redim tempArray(9)
          tempArray(0) = "13_atm"
          tempArray(1) = "13_bk_dr"
          tempArray(2) = "13_bk_wall"
          tempArray(3) = "13_drvup"
          tempArray(4) = "13_lby"
          tempArray(5) = "13_tlr_area"
          tempArray(6) = "13_tlr2"
          tempArray(7) = "13_tlr3"
          tempArray(8) = "13_vlt"
          tempArray(9) = "13_atm_rm"
          ReturnCameraList = tempArray
      Case 19 'Branch 19
          redim tempArray(13)
          tempArray(0) = "19outside"
          tempArray(1) = "19drvup1"
          tempArray(2) = "19tlr4"
          tempArray(3) = "19tlr_area"
          tempArray(4) = "19_bk_dr"
          tempArray(5) = "19_tlr_1"
          tempArray(6) = "19_bk_rm"
          tempArray(7) = "19lobby"
          tempArray(8) = "19_tlr_2"
          tempArray(9) = "19_tlr_3"
          tempArray(10) = "19drvup2"
          tempArray(11) = "19atm"
          tempArray(12) = "19_exit"
          tempArray(13) = "19usb"
          ReturnCameraList = tempArray
  End Select
  End Function
  </code></pre>
  
  <p>Any help with this would be greatly appreciated. </p>