I have a macro that uses a graphical interface. On this interface, I use 2 buttons that allow me to select specific files.
The problem is that once I use the first, it saves the file type and I once again each time the same file type as it should change. I have not understand? So here's an example!
I launch the application and click on the button that 2 is used to select a file type "*.spe". I selected my file without problem. I click the button 4, which I use to select files of type "*.lcs" and it offers me the file type "*.spe". I need to change each time the file type and that commence me inflate serious (especially behind that, it can cause a lot of mistakes! )
Here is the code!
Code:
Private Sub CommandButton4_Click ()
MsgBox ("Warning: the address must not contain spaces")
Dim fdChoice As FileDialog
Dim strNamefile As String
Set fdChoice = Application.FileDialog (msoFileDialogFilePicker) 'choose file
fdChoice.ButtonName = 'Choose' button name
fdChoice.Title = "Select a file.lcs" 'under the box
fdChoice.Filters.Add "Files.lcs", "*.lcs' filter files
fdChoice.InitialFileName = "H:" 'original record
fdChoice.AllowMultiSelect = False 'no multi selection
If fdChoice.Show = False Then
MsgBox "Setting aside"
Exit Sub
Else
strNamefile = fdChoice.SelectedItems (1) 'store the file name selected
Me.TextBox2.Value = strNamefile
MsgBox (strNamefile & "selected") 'treatment
End If
End Sub
Private Sub CommandButton2_Click ()
MsgBox ("Warning: the address must not contain spaces")
Dim fdChoiceSpe As FileDialog
Dim strNamefileSpe As String
Set fdChoiceSpe = Application.FileDialog (msoFileDialogFilePicker) 'choose file
fdChoiceSpe.Title = "Choose the file spe" 'under the box
fdChoiceSpe.Filters.Add "spe Files", "*.spe" 'filter files
fdChoiceSpe.InitialFileName = "H:" 'original record
fdChoiceSpe.AllowMultiSelect = False 'no multi selection
If fdChoiceSpe.Show = False Then
MsgBox "Setting aside"
Exit Sub
Else
strNamefileSpe = fdChoiceSpe.SelectedItems (1) 'store the file name selected
Me.TextBox1.Value = strNamefileSpe
MsgBox (strNamefileSpe & "selected") 'treatment
End If
End Sub
Bookmarks