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.
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. ...
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..
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
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
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.
When the code bugs out, go to Debug and in the Immediate Window (Ctrl+g to open) type in
and check the returned paths are absolutely correct and as expected.
the Path C:\users\desktop does exist?
not C:\users\All Users or C:\users\help_for_excel
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
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?
Office/Excel 2010 Win 10
Common sense is not so common.
I know its strange and I don't know why but when used below method worked is worked perfectly
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