J
Junya Nitta
I am using msoFileDialogOpen or msoFileDialogFilePicker to select
specific files.
After I use the procedure "FilePath_FolderPath_1" below, the other
procedure "FilePath_FolderPath_2" gives you the same filters and
button name that have been set in the procedure
"FilePath_FolderPath_1", although "FilePath_FolderPath_2" does not
have .ButtonName or .Filters.Add method.
I want the default button name and filters in the procedure
"FilePath_FolderPath_2".
Could you tell me how to reset the button name and filters into the
original condition showing the default setting.
Thanks in advance.
Sub FilePath_FolderPath_1()
Dim fd As FileDialog
Dim myFileName As String
Dim myFolderPath As String
Dim myFilePath As String
On Error GoTo EH
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Title = "Select Word Document"
.AllowMultiSelect = False
.ButtonName = "Word_Files_Open"
.Filters.Clear
.Filters.Add "All files", "*.*", 1
.Filters.Add "All Word Documents", "*.doc; *.docx", 2
.FilterIndex = 2
If .Show = -1 Then
myFilePath = .SelectedItems(1)
myFileName = Right(myFilePath, Len(myFilePath) -
InStrRev(myFilePath, "\"))
myFolderPath = Left(myFilePath, Len(myFilePath) -
Len(myFileName) - 1)
MsgBox "Folder Path:" & myFolderPath & vbCr & _
"File Path:" & myFilePath & vbCr & _
"File Name:" & myFileName
End If
End With
Set fd = Nothing
On Error GoTo 0
Exit Sub
EH:
MsgBox Err.Description
End Sub
----------------------------------------------------------------------
Sub FilePath_FolderPath_2()
Dim fd As FileDialog
Dim myFileName As String
Dim myFolderPath As String
Dim myFilePath As String
On Error GoTo EH
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Title = "Select Word Document"
.AllowMultiSelect = False
If .Show = -1 Then
myFilePath = .SelectedItems(1)
myFileName = Right(myFilePath, Len(myFilePath) -
InStrRev(myFilePath, "\"))
myFolderPath = Left(myFilePath, Len(myFilePath) -
Len(myFileName) - 1)
MsgBox "Folder Path:" & myFolderPath & vbCr & _
"File Path:" & myFilePath & vbCr & _
"File Name:" & myFileName
End If
End With
Set fd = Nothing
On Error GoTo 0
Exit Sub
EH:
MsgBox Err.Description
End Sub
specific files.
After I use the procedure "FilePath_FolderPath_1" below, the other
procedure "FilePath_FolderPath_2" gives you the same filters and
button name that have been set in the procedure
"FilePath_FolderPath_1", although "FilePath_FolderPath_2" does not
have .ButtonName or .Filters.Add method.
I want the default button name and filters in the procedure
"FilePath_FolderPath_2".
Could you tell me how to reset the button name and filters into the
original condition showing the default setting.
Thanks in advance.
Sub FilePath_FolderPath_1()
Dim fd As FileDialog
Dim myFileName As String
Dim myFolderPath As String
Dim myFilePath As String
On Error GoTo EH
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Title = "Select Word Document"
.AllowMultiSelect = False
.ButtonName = "Word_Files_Open"
.Filters.Clear
.Filters.Add "All files", "*.*", 1
.Filters.Add "All Word Documents", "*.doc; *.docx", 2
.FilterIndex = 2
If .Show = -1 Then
myFilePath = .SelectedItems(1)
myFileName = Right(myFilePath, Len(myFilePath) -
InStrRev(myFilePath, "\"))
myFolderPath = Left(myFilePath, Len(myFilePath) -
Len(myFileName) - 1)
MsgBox "Folder Path:" & myFolderPath & vbCr & _
"File Path:" & myFilePath & vbCr & _
"File Name:" & myFileName
End If
End With
Set fd = Nothing
On Error GoTo 0
Exit Sub
EH:
MsgBox Err.Description
End Sub
----------------------------------------------------------------------
Sub FilePath_FolderPath_2()
Dim fd As FileDialog
Dim myFileName As String
Dim myFolderPath As String
Dim myFilePath As String
On Error GoTo EH
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Title = "Select Word Document"
.AllowMultiSelect = False
If .Show = -1 Then
myFilePath = .SelectedItems(1)
myFileName = Right(myFilePath, Len(myFilePath) -
InStrRev(myFilePath, "\"))
myFolderPath = Left(myFilePath, Len(myFilePath) -
Len(myFileName) - 1)
MsgBox "Folder Path:" & myFolderPath & vbCr & _
"File Path:" & myFilePath & vbCr & _
"File Name:" & myFileName
End If
End With
Set fd = Nothing
On Error GoTo 0
Exit Sub
EH:
MsgBox Err.Description
End Sub