Hi Pero,
try this..half finnished code ....
Option Explicit
Sub MoveFiles()
MoveOrCopy Selection.Cells, False
End Sub
Sub CopyFiles()
MoveOrCopy Selection.Cells, True
End Sub
Sub MoveOrCopy(r As Range, bCopy As Boolean)
Dim z!, e!, a, u$, sDir$, fs As Object
On Error Resume Next
With Selection.Cells
a = .Cells
z = .Rows.Count
End With
If z = 0 Then
MsgBox "select some cells"
Exit Sub
End If
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Välj mapp"
.AllowMultiSelect = False
If .Show = 0 Then Exit Sub
sDir = .SelectedItems(1) & "\"
End With
For e = 1 To z
u = a(e, 2) & "\" & a(e, 1) & ".*"
Set fs = CreateObject("scripting.filesystemobject")
If bCopy = True Then
fs.Copyfile u, sDir
Else: fs.Movefile u, sDir
End If
Set fs = Nothing
Next
Exit Sub
Errorhandler:
If Err = "75" Then
MsgBox ("Åtkomst nekad. Kan bero på att filen är öppen eller att du inte har behörighet till filen.")
End If
If Err = "70" Then
MsgBox ("Du kan inte kopiera en öppen fil. Stäng filen och försök igen.")
Exit Sub
End If
End Sub
will have to add these checks
Sub DoesFolderExist()
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
MsgBox fs.FolderExists("C:\Program Files")
End Sub
Sub FileExists()
Dim fs As Object
Dim strFile As String
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = InputBox("Enter the full name of the file:")
If fs.FileExists(strFile) Then
MsgBox strFile & " was found."
Else
MsgBox "File does not exist."
End If
End Sub
Bookmarks