Move a file

O

Otto Moehrbach

Excel XP & Win XP
I want to move (not copy) a file from one folder to another folder. I tried
the following test macro and I got a #70 error "Permission denied" on the
"FileCopy" line of code. What is the proper code to move a file? Thanks
for your time. Otto
PS: My computer is a sole home computer, not hooked up to any network at
all.
Sub TestMove()
Dim PathSource As String
Dim PathDest As String
Dim FileName As String
PathSource = "C:\ASource\"
PathDest = "C:\ADest\"
FileName = "Test.xls"
FileCopy PathSource & FileName, PathDest & FileName
End Sub
 
H

Harald Staff

Hi Otto

Simply renaming it:

Name "C:\ASource\Test.xls" As "C:\ADest\Test.xls"

This will not solve any permission issues, you need full access to both
folders.

HTH. Best wishes Harald
 
O

Otto Moehrbach

Duh! The Test.xls file was open and that created the "Permission Denied"
error. I closed the file and the code copied the file. I then changed the
FileCopy line to:
Name PathSource & FileName As PathDest & FileName
and all was well. Thanks anyway. Otto
 
O

Otto Moehrbach

Thanks Harald. The permission issue was because I had the Test file open.
Some times I wonder. Otto
 
O

Otto Moehrbach

Thanks Dana. Otto
Dana DeLouis said:
As a side note, you will also get #70 error "Permission denied" if you
give a destination without a trailing "\" character to indicate it's a
folder.

Sub Demo()
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.MoveFile "C:\Junk A\Dummy.txt", "C:\Junk B\"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top