How to Reset ButtonName and Filters in msoFileDialogOpen?

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
 
J

Junya Nitta

I am replying to the above question of myself.

After I posted the above question, I found out that ButtonName and
Filters in msoFileDialogOpen are reset to the default condition if
Word is restarted.

Thank you for your support.

Junya Nitta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top