Results 1 to 18 of 18

Move/Copy macro doesn't work as aspected

Threaded View

  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    Stockholm,Sweden
    MS-Off Ver
    Excel 2003
    Posts
    43

    Move/Copy macro doesn't work as aspected

    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
    Last edited by Pero; 09-25-2009 at 02:49 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1