Return File Reference


/ Published in: Visual Basic
Save to your folder(s)

Used to invoke a GetSaveAsFileName dialogue box


Copy this code and paste it in your HTML
  1. Function ReturnFileReference(InitialFile As String, Title As String, InitialFolder As String, FilterTo As String) As String
  2. Dim Filter As String
  3. Dim FilterIndex As Integer
  4. Dim Filename As Variant
  5.  
  6. ' File filters
  7. Filter = FilterTo
  8.  
  9.  
  10. 'Filter = "Excel Files (*.xls),*.xls," '& _
  11.   "Text Files (*.txt),*.txt," & _
  12.   "All Files (*.*),*.*"
  13. ' Default Filter to *.*
  14.  
  15. 'FilterIndex = 1
  16. ' Set Dialog Caption
  17. ' Select Start Drive & Path
  18. ChDrive (Left(InitialFolder, 1))
  19. ChDir (InitialFolder)
  20.  
  21. With Application
  22. ' Set File Name to selected File
  23. 'Filename = .GetOpenFilename(Filter, FilterIndex, Title)
  24. Filename = .GetSaveAsFilename(InitialFile, Filter, FilterIndex, Title)
  25. ' Reset Start Drive/Path
  26. ChDrive (Left(.DefaultFilePath, 1))
  27. ChDir (.DefaultFilePath)
  28. End With
  29. ' Exit on Cancel
  30. If Filename = False Then
  31. ReturnFileReference = "NO_FILE_SELECTED"
  32. Exit Function
  33. End If
  34.  
  35. ReturnFileReference = Filename
  36.  
  37. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.