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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,223,970
Messages
6,175,703
Members
452,667
Latest member
vanessavalentino83

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