+ Reply to Thread
Results 1 to 2 of 2

macro for copying file

Hybrid View

Guest macro for copying file 08-24-2005, 03:05 AM
Guest Re: macro for copying file 08-24-2005, 10:05 AM
  1. #1
    Joseph
    Guest

    macro for copying file

    How to write a macro which copies a file in one loacation (source location)
    to other folder (destination).
    I used the function FileSystemObject.CopyFile
    "c:\mydocuments\letters\*.doc", "c:\tempfolder\" but it returned error.
    Can any one help me.

    Regards,
    Joseph

  2. #2
    Dave Peterson
    Guest

    Re: macro for copying file

    My bet is you don't have a folder named "c:\mydocuments\letters" or you don't
    have a folder named "C:\tempfolder" or you don't have any *.doc files in that
    source folder.

    (c:\mydocuments could be c:\my documents (with that space character).)

    But you could check each before you try it:

    Option Explicit
    Sub testme()

    '' With a reference (tools|references) to microsoft scripting runtime
    ' Dim FSO As Scripting.FileSystemObject
    ' Dim myDrive As Scripting.Drive
    ' Set FSO = New Scripting.FileSystemObject

    ' without that reference
    Dim FSO As Object
    Dim myDrive As Object
    Set FSO = CreateObject("scripting.filesystemobject")

    Dim mySourceFolder As String
    Dim myDestFolder As String
    Dim testStr As String

    mySourceFolder = "C:\my documents\excel"
    myDestFolder = "C:\temp"

    If FSO.FolderExists(mySourceFolder) = False Then
    MsgBox mySourceFolder & " doesn't exist"
    Exit Sub
    End If

    If FSO.FolderExists(myDestFolder) = False Then
    MsgBox myDestFolder & " doesn't exist"
    Exit Sub
    End If

    testStr = ""
    On Error Resume Next
    testStr = Dir(mySourceFolder & "\*.doc")
    On Error GoTo 0

    If testStr = "" Then
    MsgBox "no .Doc files in: " & mySourceFolder
    Exit Sub
    End If

    FSO.CopyFile mySourceFolder & "\*.doc", myDestFolder

    End Sub

    Joseph wrote:
    >
    > How to write a macro which copies a file in one loacation (source location)
    > to other folder (destination).
    > I used the function FileSystemObject.CopyFile
    > "c:\mydocuments\letters\*.doc", "c:\tempfolder\" but it returned error.
    > Can any one help me.
    >
    > Regards,
    > Joseph


    --

    Dave Peterson

+ Reply to Thread

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