Excel VBA FILECOPY

help_for_excel

Board Regular
Joined
Feb 24, 2012
Messages
72
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
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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.
 
Upvote 0
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:
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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 .
 
Upvote 0
I know its strange and I don't know why but when used below method worked is worked perfectly

http://forums.devarticles.com/microsoft-access-development-49/copy-file-using-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
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top