ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving a file using excel vba (https://www.excelbanter.com/excel-programming/358814-moving-file-using-excel-vba.html)

Greg[_20_]

Moving a file using excel vba
 
Hi all I am looking to use excel to move a file when necessary. i.e.

I need to move a file called darts.xls to the folder c:\games

Thanks

Greg



RB Smissaert

Moving a file using excel vba
 
Look at the FileCopy and Kill statements in the VBA help.

RBS

"Greg" wrote in message
...
Hi all I am looking to use excel to move a file when necessary. i.e.

I need to move a file called darts.xls to the folder c:\games

Thanks

Greg




Peter81[_10_]

Moving a file using excel vba
 

I dont think there is an explict Move statement in vb so I think you
would need to use something like:

FileCopy(Source As String, Destination As String)
then
Kill(Source As String)

e.g
FileCopy "d:\games\darts.xls", "c:\games\darts.xls"

Kill "d:\games\darts.xls"

Pete


--
Peter81
------------------------------------------------------------------------
Peter81's Profile: http://www.excelforum.com/member.php...o&userid=25353
View this thread: http://www.excelforum.com/showthread...hreadid=532626


DS

Moving a file using excel vba
 
Peter81 - thanks very much for this post. For some time, when users are
submitting information on a form, I've been using the "SaveAs" command to
save a copy of the completed pro forma in a separate folder. This, of course,
leaves the user in the "Saved As" copy following this, rather than in the
template, which means they have to close the open document, and reopen the
template in order to submit another. Using this FileCopy method will make
their lives (and therefore mine!) much, much easier.

Many Thanks for that!
DS

"Peter81" wrote:


I dont think there is an explict Move statement in vb so I think you
would need to use something like:

FileCopy(Source As String, Destination As String)
then
Kill(Source As String)

e.g
FileCopy "d:\games\darts.xls", "c:\games\darts.xls"

Kill "d:\games\darts.xls"

Pete


--
Peter81
------------------------------------------------------------------------
Peter81's Profile: http://www.excelforum.com/member.php...o&userid=25353
View this thread: http://www.excelforum.com/showthread...hreadid=532626



Bob Phillips[_6_]

Moving a file using excel vba
 
Look at Name

sOldName = "myFile.xls"
sNewName = "c:\some other dir\its subdir\myNwFile.xls"
Name sOldName As sNewName

It won't create the directories if they don't exist so you can just do that
like so

On Error Resume Next
MkDir "c:\some other dir\its subdir"
MkDir "c:\some other dir\its subdir\myNwFile.xls"
On Error Goto 0

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Greg" wrote in message
...
Hi all I am looking to use excel to move a file when necessary. i.e.

I need to move a file called darts.xls to the folder c:\games

Thanks

Greg





Bob Phillips[_6_]

Moving a file using excel vba
 
You could use SaveCopyAs

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DS" wrote in message
...
Peter81 - thanks very much for this post. For some time, when users are
submitting information on a form, I've been using the "SaveAs" command to
save a copy of the completed pro forma in a separate folder. This, of

course,
leaves the user in the "Saved As" copy following this, rather than in the
template, which means they have to close the open document, and reopen the
template in order to submit another. Using this FileCopy method will make
their lives (and therefore mine!) much, much easier.

Many Thanks for that!
DS

"Peter81" wrote:


I dont think there is an explict Move statement in vb so I think you
would need to use something like:

FileCopy(Source As String, Destination As String)
then
Kill(Source As String)

e.g
FileCopy "d:\games\darts.xls", "c:\games\darts.xls"

Kill "d:\games\darts.xls"

Pete


--
Peter81
------------------------------------------------------------------------
Peter81's Profile:

http://www.excelforum.com/member.php...o&userid=25353
View this thread:

http://www.excelforum.com/showthread...hreadid=532626





Greg[_20_]

Moving a file using excel vba
 
Thanks Everyone for your help will try all.

Greg
"Bob Phillips" wrote in message
...
Look at Name

sOldName = "myFile.xls"
sNewName = "c:\some other dir\its subdir\myNwFile.xls"
Name sOldName As sNewName

It won't create the directories if they don't exist so you can just do

that
like so

On Error Resume Next
MkDir "c:\some other dir\its subdir"
MkDir "c:\some other dir\its subdir\myNwFile.xls"
On Error Goto 0

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Greg" wrote in message
...
Hi all I am looking to use excel to move a file when necessary. i.e.

I need to move a file called darts.xls to the folder c:\games

Thanks

Greg








All times are GMT +1. The time now is 01:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com