Hi.
Got a code that will save all selected files in a directory chosen by the user.
Often it works great but sometimes it doesn't copy/move all the selected files, just a few (about 5-6) and sometimes the new files are just 1kb and doesn't work like the program only copied the icon.
Anyone knows a diffrent way of writing this code ? A code that doesn't bugg ?
My Code:
Sub MoveFiles()
MoveOrCopy Selection.Cells, False
End Sub
Sub CopyFiles()
MoveOrCopy Selection.Cells, True
End Sub
Private Sub MoveOrCopy(r As Range, bCopy As Boolean)
Dim cell As Range
Dim sDir As String
Dim sFile As String
Dim nFile As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Välj mapp"
.AllowMultiSelect = False
If .Show = 0 Then Exit Sub
sDir = .SelectedItems(1) & "\"
End With
For Each cell In Selection.Cells
If Len(cell.Text) Then
sFile = Mid(cell.Text, InStrRev(cell.Text, "\") + 1)
If Len(Dir(cell.Text)) Then
If bCopy Then
FileCopy cell.Text, sDir & sFile
Else
Name cell.Text As sDir & sFile
End If
nFile = nFile + 1
Else
MsgBox "Går inte att flytta: " & cell.Text
End If
End If
Next cell
MsgBox IIf(bCopy, "Kopierat ", "Flyttat ") & nFile & " fil(er)"
End Sub
Bookmarks