ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving a disk file with VBA (https://www.excelbanter.com/excel-programming/330288-moving-disk-file-vba.html)

Chris Ferguson

Moving a disk file with VBA
 
Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another using
VBA.

The reason for this is that I have an odbc link to a database and I want to
use it to read a different database without having to rebuild the query. I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to change
the database just copy the new database over the top. But I want to do this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris



quartz[_2_]

Moving a disk file with VBA
 
Chris, you can call the following function or just insert the "FileCopy" line
where you want it and replace the arguments with the full paths (i.e. drive,
path, file name, file extension):

Public Function FileCopy(argFullSourceName As String, argFullDestinationName
As String)
'COPY A CLOSED FILE FROM ONE FOLDER TO ANOTHER;
FileCopy argFullSourceName, argFullDestinationName
End Function

HTH

"Chris Ferguson" wrote:

Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another using
VBA.

The reason for this is that I have an odbc link to a database and I want to
use it to read a different database without having to rebuild the query. I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to change
the database just copy the new database over the top. But I want to do this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris




Don Guillett[_4_]

Moving a disk file with VBA
 
this should do it
Sub movefile()
OldName = "C:\oldfolder\1065.xls"
NewName = "C:\newfolder\1065.xls"
Name OldName As NewName
End Sub

--
Don Guillett
SalesAid Software

"Chris Ferguson" wrote in message
...
Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another using
VBA.

The reason for this is that I have an odbc link to a database and I want

to
use it to read a different database without having to rebuild the query.

I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to change
the database just copy the new database over the top. But I want to do

this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris





Tom Ogilvy

Moving a disk file with VBA
 
Just some added info:
Even though the OP said move in his subject, he said copy in the body. the
Name command will move the file. The Filecopy command will copy it.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
this should do it
Sub movefile()
OldName = "C:\oldfolder\1065.xls"
NewName = "C:\newfolder\1065.xls"
Name OldName As NewName
End Sub

--
Don Guillett
SalesAid Software

"Chris Ferguson" wrote in message
...
Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another

using
VBA.

The reason for this is that I have an odbc link to a database and I want

to
use it to read a different database without having to rebuild the query.

I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to

change
the database just copy the new database over the top. But I want to do

this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris







Chris Ferguson

Moving a disk file with VBA
 
Brilliant, thanks guys, the copyfile was exactly what I wanted.

Why is it so obvious, just after it has been pointed out?

Chris
"Tom Ogilvy" wrote in message
...
Just some added info:
Even though the OP said move in his subject, he said copy in the body. the
Name command will move the file. The Filecopy command will copy it.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
this should do it
Sub movefile()
OldName = "C:\oldfolder\1065.xls"
NewName = "C:\newfolder\1065.xls"
Name OldName As NewName
End Sub

--
Don Guillett
SalesAid Software

"Chris Ferguson" wrote in message
...
Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another

using
VBA.

The reason for this is that I have an odbc link to a database and I
want

to
use it to read a different database without having to rebuild the
query.

I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to

change
the database just copy the new database over the top. But I want to do

this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris









Chris Ferguson

Moving a disk file with VBA
 
Brilliant.

Thats just what I wanted.

Thanks very much.
"Tom Ogilvy" wrote in message
...
Just some added info:
Even though the OP said move in his subject, he said copy in the body. the
Name command will move the file. The Filecopy command will copy it.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
this should do it
Sub movefile()
OldName = "C:\oldfolder\1065.xls"
NewName = "C:\newfolder\1065.xls"
Name OldName As NewName
End Sub

--
Don Guillett
SalesAid Software

"Chris Ferguson" wrote in message
...
Hi

Can someone point me in the right direction please.
I want to copy an access database from one disk location to another

using
VBA.

The reason for this is that I have an odbc link to a database and I
want

to
use it to read a different database without having to rebuild the
query.

I
have found that for me the easiest way to do this is to copy the live
database into a temporary location which msquery can read, then to

change
the database just copy the new database over the top. But I want to do

this
all from within excel.

So any pointerswould be appreciated.

Many Thanks

Chris










All times are GMT +1. The time now is 04:18 PM.

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