Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Joseph
 
Posts: n/a
Default 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   Report Post  
Dave Peterson
 
Posts: n/a
Default

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel macro that opens new MS Word file and pastes data as a pictu Rob Excel Worksheet Functions 0 July 6th 05 05:12 PM
Problem Editing Macro in Shared Excel File [email protected] Excel Discussion (Misc queries) 0 March 19th 05 06:01 PM
open file (as variable) from macro d chaps Excel Discussion (Misc queries) 1 March 14th 05 11:57 PM
creat a macro to look for a file Kelly****** Excel Discussion (Misc queries) 1 January 2nd 05 09:24 AM
This one is tricky....Macro to save file as cell value x in di Andy Excel Discussion (Misc queries) 4 November 26th 04 08:52 AM


All times are GMT +1. The time now is 10:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"