Results 1 to 10 of 10

Excel VBA FILECOPY

This is a discussion on Excel VBA FILECOPY within the Excel Questions forums, part of the Question Forums category; hi, I am running into interesting situation I am using below Line of code, and it works every time fine. ...

  1. #1
    Board Regular
    Join Date
    Feb 2012
    Posts
    72

    Default Excel VBA FILECOPY

    hi,


    I am running into interesting situation I am using below Line of code, and it works every time fine. source file is like 10MB (file1)

    FileCopy "C:\Users\Desktop\file1.pptx", "C:\Users\Desktop\file2.pptx"

    but when I try to run below code is gives me error and that only sometimes. I put the watch expression and both have same string as above but still doesn't execute every time..
    (Error 75)

    FileCopy Copy_PPT, Paste_PPT


    I have to pass down string in variable form.....can anyone please help....is it something to memory


    thanks in advance

  2. #2
    Board Regular
    Join Date
    Dec 2011
    Posts
    3,638

    Default Re: Excel VBA FILECOPY

    Can you show your code where you are assigning the paths to the variables as I suspect it is a problem with the Path construction.
    For testing your Regular Expression patterns, try my Regular Expression Pattern Testing add-in!

    For notes on how to use it - see here.

  3. #3
    Board Regular
    Join Date
    May 2011
    Location
    London
    Posts
    1,722

    Default Re: Excel VBA FILECOPY

    Error 75

    this is not necessarily a code problem, considering you've said it works

    Its probably some issue with the files/Paths you are copying to

    see below for pointers

    http://msdn.microsoft.com/en-us/libr...(v=vs.60).aspx

  4. #4
    Board Regular
    Join Date
    Feb 2012
    Posts
    72

    Default Re: Excel VBA FILECOPY

    here is the code

    Private Sub Copy_Paste()

    Dim Paste_ppt_loc As String
    Dim Copy_ppt_loc As String

    'code copy and paste file from one location to another
    'FileCopy "C:\Users\Desktop\file1.pptx", "C:\Users\Desktop\file2.pptx"

    Copy_ppt_loc = Range("copy_file_loc") 'this is an excel range which contains C:\Users\Desktop\file1.pptx
    Paste_ppt_loc = Range("paste_file_loc") & "\file2.pptx" 'this is an excel range which contains "C:\Users\Desktop", file name is given from vba code

    FileCopy Copy_ppt_loc, Paste_ppt_loc



    so when i run code in directly by mentioning path....it runs fine.
    but when i run code other way it gives me error 75.
    Last edited by help_for_excel; Mar 21st, 2012 at 10:23 AM.

  5. #5
    Board Regular
    Join Date
    Dec 2011
    Posts
    3,638

    Default Re: Excel VBA FILECOPY

    When the code bugs out, go to Debug and in the Immediate Window (Ctrl+g to open) type in

    ?Copy_ppt_loc

    ?Paste_ppt_loc

    and check the returned paths are absolutely correct and as expected.
    For testing your Regular Expression patterns, try my Regular Expression Pattern Testing add-in!

    For notes on how to use it - see here.

  6. #6
    Board Regular
    Join Date
    May 2011
    Location
    London
    Posts
    1,722

    Default Re: Excel VBA FILECOPY

    the Path C:\users\desktop does exist?

    not C:\users\All Users or C:\users\help_for_excel

  7. #7
    Board Regular
    Join Date
    Feb 2012
    Posts
    72

    Default Re: Excel VBA FILECOPY

    Nope it doesn't help.

    Another thing I can see that when I am opening the file problem it is opening as Read only file the one pasted

  8. #8
    Board Regular
    Join Date
    May 2011
    Location
    London
    Posts
    1,722

    Default Re: Excel VBA FILECOPY

    is the copy from file read-only?



    Is there another directory that you can use to test this that you know you have full permissions too?

  9. #9
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    4,965

    Default Re: Excel VBA FILECOPY

    Quote Originally Posted by help_for_excel View Post
    Nope it doesn't help.

    Another thing I can see that when I am opening the file problem it is opening as Read only file the one pasted
    That indicates "C:\Users\Desktop\file2.pptx" file is open and that's probably why you are getting an error. Check if its hidden in the current ppt session or in a seperate seesion via the in the Task manager .
    Office/Excel 2007 Win XP

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  10. #10
    Board Regular
    Join Date
    Feb 2012
    Posts
    72

    Default Re: Excel VBA FILECOPY

    I know its strange and I don't know why but when used below method worked is worked perfectly

    http://forums.devarticles.com/micros...vba-30811.html



    Dim fs As Object
    Dim oldPath As String, newPath As String
    oldPath = "C:\Documents and Settings\user\My Documents" 'Folder file is located in
    newPath = "C:\Documents and Settings\user\My Documents\Misc" 'Folder to copy file to
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.CopyFile oldPath & "\" & "Query1.xls", newPath & "\" & "Query1.xls" 'This file was an .xls file
    Set fs = Nothing



    thanks for your help

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com