Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim objShell
Dim strFileName
Dim strFilePath
Dim objFile
Set objShell = CreateObject("Shell.Application")
Set objFile = objShell.BrowseForFolder(0, "Choose a file:", &H4000)
strFileName = objFile.Title
strFilePath = objFile.self.Path
MsgBox "Just the file name: " & strFileName & vbcrlf & "The full path: " & strFilePath
Set objFileName = Nothing
Set objFilePath = Nothing
Set objShell = Nothing
[green]'set the type of dialog box you want to use
'1 = Open
'2 = SaveAs
'3 = File Picker
'4 = Folder Picker[/green]
Const msoFileDialogOpen = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
Set WshShell = CreateObject("WScript.Shell")
[green]'where you want to start looking for files
'You could use a string like "C:\Somefolder\Somefolder\"
'I chose to use the desktop folder of whoever was running the script. On Windows 7 it's "C:\Users\Username\Desktop\"
'Run "set" from a command prompt to see the available environment variables[/green]
strInitialPath = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\"
[green]'set the dialog box to open at the desired folder[/green]
objWord.ChangeFileOpenDirectory(strInitialPath)
With objWord.FileDialog(msoFileDialogOpen)
[green]'set the window title to whatever you want[/green]
.Title = "Select the file to process"
[green]'I changed this to false because I'm working with one file at a time[/green]
.AllowMultiSelect = False
[green]'Get rid of any existing filters[/green]
.Filters.Clear
[green]'Show only the desired file types
'for each desired group of file types, add a "Filters.Add" line with a different description and desired extensions
'the dialog box will open using whichever filter is first
'you can switch to a different filter from a drop-down list on the dialog box[/green]
.Filters.Add "All Files", "*.*"
.Filters.Add "Excel Files", "*.xls;*.xlsx"
.Filters.Add "Text Files", "*.txt"
.Filters.Add "Various Files", "*.xls;*.doc;*.vbs"
[green]'-1 = Open the file
' 0 = Cancel the dialog box
'-2 = Close the dialog box
'If objWord.FileDialog(msoFileDialogOpen).Show = -1 Then 'long form[/green]
If .Show = -1 Then [green]'short form[/green]
[green]'Set how you want the dialog window to appear
'it doesn't appear to do anything so it's commented out for now[/green]
[green]'0 = Normal
'1 = Maximize
'2 = Minimize
'objWord.WindowState = 2
'the Word dialog must be a collection object
'even though I'm using one file, I had to use a For/Next loop
'"File" returns a string containing the full path of the selected file
'For Each File in objWord.FileDialog(msoFileDialogOpen).SelectedItems 'long form[/green]
For Each File in .SelectedItems [green]'short form[/green]
[green]'Change the Word dialog object to a file object for easier manipulation[/green]
Set objFile = fso.GetFile(File)
[green]'Display the full path to the file[/green]
WScript.Echo objFile.Path
[green]'Display the path to the folder that the file is in[/green]
WScript.Echo objFile.ParentFolder
[green]'Display just the name of the file[/green]
WScript.Echo objFile.Name
Next
Else
End If
End With
[green]'Close Word[/green]
objWord.Quit