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.

Joseph1 (69)
8/24/2005 6:17:01 AM
excel.misc 78881 articles. 5 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 44

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
petersod (12004)
8/24/2005 1:07:47 PM

Similar Artilces:

How can I open a file saved in Pub 2000 version 6 in Pub 2000 ver.
The file is saved in Publisher 2000 v6 and I am trying to open it with Publisher 2000 v9. can this be done? Hi LaTrice (LaTrice, in the newsgroups you posted: || The file is saved in Publisher 2000 v6 and I am trying to open it || with Publisher 2000 v9. can this be done? No. There is no such thing as Publisher 2000 v9, nor is there a version 9 of Publisher, yet. Verify the version of Publisher that you have, and also verify the version of Publisher that you received the file from then post back. -- Brian Kvalheim Microsoft Publisher MVP http://www.publi...

copy of exchange 2000
I don't suppose microsoft is providing Exchange 2000 as a free download anywhere are they?? Until we can afford to move up to SBS 2008 (hopefully later this year), I want to trash our SBS 2000 (too many issues with it) and simply install a win2k server with Exchange until we can move on. We are not using any of the other SBS components any longer anyway... If anyone knows where I might be able to get this from, I would be very appreciative! Thanks, Brad Why not look at BPOS? $10 per user a month it's a great inexpensive solution. You may find you do not ne...

Printing Multiple Copies #4
Hi all - I am using Vista Business and Publisher 2007 from the Office 2007 Small Business package. No matter what type of publication or template I use I can only print single copies. Most recently I tried to print 30 copies of a single page flyer and had to do it a single copy at a time. If I go to File|Print and set the number of copies to 30, I still get a single copy only. Does anyone have any thoughts? Thanks -- Andrew Aitchison ( Is your printer driver current? What is the default in the printing preferences in the control panel printer folder? ...

automatically naming files for savingb
Hi, for delivery notes i would like excel to look in the relative directory for a given customer, ie if C4 contains superspecs, files relating to this account would be in c:\work\superspecs\ files are named superspecsdel0001,superspecsdel0002.......etc superspecsinv0001...etc for delivery notes and invoices. what i would like is a line (or more) to add to a macro which will look in the appropriate directory, add 1 to the last four digits of the last file, enter this number into a cell on the sheet and save the new file with the appropriate name, then close the file. is this possible, or alte...

why do changes only save locally on networked excel file?
why do changes only save locally on networked excel file? ...

How to get a macro to do what i want?
I have designed a form in Excel and the data that is inputted i want to be able to save in a separate worksheet. The problem i am having is that eveytime i record the macro, it over writes the same row each time (if that makes sense). For example if i copied every cell in the form and paste them into the database Row 1, i then want the new piece of information inputted into the form to go into Row 2 and then Row 3 etc.... But it keeps going into Row 1, it wouldnt move down the rows. Hopefully this makes sense to someone and someone can give me some advise. Calculate the last row ...

Macro to apply alternate grey/white shading to selected paragraphs
Dear Experts: I would like to do paragraph shading using grey shading alternately. Example: this is a sample text This is another sample text This is yet another sample text This may be the last paragraph acquiring grey shading This is the penultimate paragraph This is the last paragraph With these 6 paragraphs selected, I would like to run a macro which applies grey shading alternately to the selected paragraphs, i.e. grey/ white (no shading) alternately. Help is much appreciated. Thank you very much in advance. Regards, Andreas Use Dim oRng As Range For i = 2 T...

Outlook should keep files in the clipboard after closing a window
When you open a message (in a new window) in Outlook 2007, and copy one or more files contained in this message, and then close the window, the file is not kept in the clipboard. I have to copy the file and paste it before closing the window. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I ...

Insert Static Date as part of Macro
I've built a nice macro, but I want it to insert the date it is run in an empty cell within the macro's range. When working within a spreadsheet, Ctrl +; returns the system date, but I can't figure out how to put that command into a macro. The macro recorder editor shows that the system recognizes the entry as the current date, not a function that returns the current date. The now() or today() functions are both dynamic ... they change with the system date. That's not acceptable in this situation. I need to seen when the macro was run. Thanks for any help, Ralph di...

Macro Security, Password Recovery & VB Code execution
I have found that if I set my macro security to high, VB code within (non-trusted) excel sheets do not execute... a microsoft security feature that ostensibly prevents non- trusted users from running VB The questions I have are : Is there a way to guarantee VB macro-execution using digital certificates or what-have-you ? Is there a way to detect, either within excel (well, not possible, it seems) or from outside, that the combo of users macro-security settings and signature status of a perticular excel file, WILL prevent VB from executing, if the file is attempted to opened ? ...

Deleted file in Outlook
I accidentaly deleted a folder in Outlook 2003 and am wondering if it possible to retreive it. Thank you, Karl <> wrote: > I accidentaly deleted a folder in Outlook 2003 and am wondering if it > possible to retreive it. Unless you permanently deleted it (i.e., held down Shift when pressing Delete), it will be in your Deleted items folder, unless you've emptied that folder. If you have emptied it, other suggestions depend on knowing what data store you're using (PST or Exchange mailbox). -- Brian Tillman ...

Copy Data from One Group of Cells to Another Group
I have five columns of data on two different sheets in the same workbook. One set of columns is sorted in ascending date order the other in descending date order. When I enter data into the last row of Sheet 1, I need the data in that row in columns A, B, C and D to be copied into Sheet 2 columns A, C, D and E in a newly inserted row 14. Is this possible with the use of a macro? I can find the last cell in Sheet 1, but then need to go up one row and back to column A. I am having difficulty with that. Thanks is advance for any assistance offered! /s/ Alan Auerbach On Sat, 26 May 2007, ...

Macros and Active X
My ctrl+c and ctrl+v shortcuts dont work unless I turn on my active forms bar to edit mode. Any guesses why -- Message posted from Because the spreadhseet is "live". You have to go into edit mode t make any changes to control toolbox items. -- Message posted from I'm not trying to edit my active x forms, The problems is that th standard ctrl+c and ctrl+v copy and paste short cuts wont work unles the active x edit mode is turned on. I don't have to turn on the active x edit mode to use these short cut in other wo...

Copy cell contents, then paste into the same cell with other text.
Hi! I tried a search first and couldn't find anything like this. My spreadsheet has a column for shipping that takes a series like this for each product: ?0.0*0.13.2*d*0x0x0:07:24:04 Following the question mark is the handling charge (0.0 in this example). This is followed by an * and then the weight of the item (0.13.2 in this example which is 13.2 ounces) I have a list of product weights in a colum with just pounds and ounces. I need to copy that information, then paste it into the weight area of the string above and then paste those modified contents back into t...

Find Replace with Macro
Can anyone tell me how to construct a macro that will seacrh the entire contents of column C, find the contacts of cell A1 and replace it with B1, then do the same finding A2 and replacing it with B2 in column C, then A3 with B3 in column C etc etc. I can not get this to work. Sub Test() Dim r1 as Range Dim r2 as Range For Each r1 in Range("A1:A" & Range("A65536").End(xlUp).Row For Each r2 in Range("C1:C" & Range("C65536").End(xlUp).Row If r1.Value = r2.Value Then r2.Value = Range("B" & r1.Row).Value Next Next End Sub -...

XML File Converter for MS 2004
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: intel I'm a high school teacher. I write power points on MS 2004 on my Mac and transfer them to my school's PC that has MS 2003. This worked great, with exception of minor formatting changes, until a month ago. Power points that I previously opened on that PC, along with new ones, would not open - this is disasterous for instruction. My tech says 1) the school's PC may have had updates that caused the new problem and 2) that I should install the Open XML File Converter for Mac's MS 2004. I'm concerned tha...

copy and clear sheets with VBA
I have a template sheet that users fill in, this creates calculations and a graph on another worksheet. I have a command button that copies the worksheet and renames it and writes to a data bank. It also clears the original template. However when it clears the template all copied worksheets clear as well. what can I do ??? Please help --- Message posted from Hi jlong, Right off the top of my head it sounds like when you're copying th worksheets, their linking and retaining those link. So when you clea the 'master' they clear as well. could you post...

how do I transfer file from Clipboard to an e-mail message
How do I transfer a file from Outlook clipboard or C drive to the body of an e-mail message NOT as an attachment. thanks you would need to open the file and copy the contents. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Need Help with Common Tasks? Outlook Tips: Outlook & Exchange Solutions Center: Subscribe to Exchange Messaging Outlook newsletter: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOF...

Transferring files to a new computer
Hi - I'm in the process of configuring my new Windows XP with MSFT Small Biz. I was running Windows 98 and using Outlook 2000. Now I want to copy all my old emails, folders, addresses etc. into the new version of Outlook 2003 but I can't seem to find it. It's not recognizing my saved files as .PST files. Does anyone know how to do this? Thanks, daviskho "daviskho" <> wrote in message news:052801c3dbb0$e46e5970$a101280a@phx.gbl... > Hi - I'm in the process of configuring my new Windows XP > with MSFT Small Biz. ...

Too large to send, yet the file gets saved.
I noticed that a user's mailbox grew from 100KB to 400KB in a few days. This got my attention. I pokjed around and found that he had tried to zip a really big file and send it to his AOL account. (we won't talk about what was in that single file that would not compress al that well :-) ) The file was 161MB (obviously this is larger than global message delivery default) and it was in both his sent items and found in the bounce-back message from the system administrator: This message is larger than the current system limit or the recipient's mailbox is full. Create a shorter messa...

Copy cell to a new cell #2
In Column B I have certain values which start with GB2 e.g GB2-02210. I would to like to copy these values and paste it in another cell. I would like to do this with only values which start with GB2. Many thanks -- Message posted via I would use Data>Filter>Autofilter and use custom>begins with... -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England "mohd21uk via" <u20517@uwe> wrote in message news:5ede27c5beb13@uwe... > In Column B I have certain values ...

Opening multiple workbooks through code and copying values
Help! the following code 'kinda sorta' does what I want, but it has 3 problems. 1. Instead of going on to the next file if the file doesn't exist, it pastes the data from the previous file. 2. It closes the workbook into which I am compiling data instead of just the ones I am copying from. 3. Everytime it closes a file, it asks the question about 'large amounts of data in the clipboard.' Thanks, Pam Here is the code: Private Sub cmdCreate_Click() On Error GoTo Report_Err Dim myPath As String Dim myReport As Object Dim mySheet As String Dim myRow As Integer Dim x...

Capital One giving me corrupt Money import files
Money is saying the files I get from Capital One credit card are corrupt. Some months import fine, while others I get an error. I try to get support from Capital One, but they keep giving me the runaround. Anything I can do with Money to get this to work? I have about 50 transactions a month and rather not input these manually! -Max Max, The problem is that there's a character in the statement you're getting from Capital One that Money is choking on. I've run in to the same the statement from Capital One to your hard drive and edit it by hand. Search for &qu...

copy utility
Hi The copy/paste function in windows explorer is not good enough. If it cannot read one file during the copy process, explorer just give error message and skip all remaining files. Then I have no idea how may files have been copied unless to compare. It is painful when I copy huge amount of files. Is there any utility can solve this problem? "wu" <> wrote in message news:#cKaZQy4KHA.1888@TK2MSFTNGP05.phx.gbl... > Hi > > The copy/paste function in windows explorer is not good enough. If it > cannot read one file d...

jpg files
I have had several users experiencing problems opening pictures from Outlook 2000. Their O/S is XP Pro. Any ideas? Thank You, Jamie ...