FileCopy but permission denied

jscholds

New Member
Joined
Mar 28, 2004
Messages
7
Hi,

I would like to copy and create a backup of a file that is open by users.

Have tried:

Dim sSourcePath As String, sDestPath As String

sSourcePath = "C:\testfile.DBF"
sDestPath = "C:\testfile_copy.DBF"

FileCopy sSourcePath, sDestPath

Obviously I get an error as the file is open, however is there any way I can copy the file with FileCopy or any other syntax?

Would it be possible to open the file as a "copy" then save it?

Not very familiar with VBA - would really appreciate some help on this!!

Regards,

Jakob
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Jakob welcome to the board! Here's some code to copy files.
Code:
sub copythatfile
Dim xlobj as object
Set xlobj = CreateObject("Scripting.FileSystemObject")
'object.copyfile,source,destination,file overright(True is default)
xlobj.CopyFile "c:\bob\bob3.xls", "c:\bob\copybob3.xls", True
Set xlobj = Nothing
end sub
This copies the wb bob3.xls in folder bob in "C" directory to copybob3.xls also in folder bob in "C" directory. Hope this is what you're looking for. Dave
 
Upvote 0
Jakob welcome to the board! Here's some code to copy files.
Code:
sub copythatfile
Dim xlobj as object
Set xlobj = CreateObject("Scripting.FileSystemObject")
'object.copyfile,source,destination,file overright(True is default)
xlobj.CopyFile "c:\bob\bob3.xls", "c:\bob\copybob3.xls", True
Set xlobj = Nothing
end sub
This copies the wb bob3.xls in folder bob in "C" directory to copybob3.xls also in folder bob in "C" directory. Hope this is what you're looking for. Dave
This is great code!! thank you
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,587
Members
449,174
Latest member
chandan4057

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