1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
Private Sub CommandButton1_Click()
On Error Resume Next
With Application.GetOpenFilename
.AllowMultiSelect = False
.Show
UserForm1.TextBox1.Text = .SelectedItems(1)
End With
'display the path in the text box
Dim Path As String
TextBox1.Value = Workbooks(ActiveWorkbook.Name).FullName
End Sub
Private Sub Send_Click()
Dim file As String, Path As String
file = SelectedItems
Path = TextBox1.Value
'Copy the file in the repertory where there is the database
On Error GoTo err
'If there is a problem, go to the end without add the file
Dim SourceFile, New_path
SourceFile = Path ' Defines the name and path source file
New_path = ThisWorkbook.Path & "\" & file ' Defines the file name and the new path target
'Copy the source file in the target file
FileCopy SourceFile, New_path
On Error GoTo 0
'Now, if there is a problem, the system don't go to the end.
End Select
'Deconnection
Cnx.Close
'Hide the userform Link
Link.Hide
'Msgbox in order to tell that there is no problem
MsgBox ("OK")
Exit Sub
'Error when the program want to copy the file.
err:
MsgBox ("The file not found.")
End Sub |
Partager