ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy files from one dir to another (https://www.excelbanter.com/excel-programming/290977-copy-files-one-dir-another.html)

rvik[_14_]

copy files from one dir to another
 
hai

a cell address contains a file name. i want the file name in the cel
address to be the input for the code below, so that the file is copie
to a new location....i.e. instead of the "test.doc", i should have th
file name mentioned in the cell address


Sub file_trf_copy()
oldname = "C:\test.doc"
newname = "\\....\test.doc"
FileCopy oldname, newname
End Sub
test.do

--
Message posted from http://www.ExcelForum.com


Nikos Yannacopoulos[_5_]

copy files from one dir to another
 
oldname = Range("B3").value

where I have assumed the file name is in B3. Change accordingly.

HTH,
Nikos

"rvik " wrote in message
...
hai

a cell address contains a file name. i want the file name in the cell
address to be the input for the code below, so that the file is copied
to a new location....i.e. instead of the "test.doc", i should have the
file name mentioned in the cell address


Sub file_trf_copy()
oldname = "C:\test.doc"
newname = "\\....\test.doc"
FileCopy oldname, newname
End Sub
test.doc


---
Message posted from http://www.ExcelForum.com/




Jim Rech

copy files from one dir to another
 
To assign the value of a cell to a variable use code like:

Dim MyStr as String
MyStr = Range("A1").Value

or

MyStr =Range("MyCell").Value

The latter uses a named cell and is better in general than a hardwired cell
address like "A1" because you do not have to change your code if you happen
to insert a row above the cell in question.

--
Jim Rech
Excel MVP



Don Guillett[_4_]

copy files from one dir to another
 
NewName = ActiveCell.Value

--
Don Guillett
SalesAid Software

"rvik " wrote in message
...
hai

a cell address contains a file name. i want the file name in the cell
address to be the input for the code below, so that the file is copied
to a new location....i.e. instead of the "test.doc", i should have the
file name mentioned in the cell address


Sub file_trf_copy()
oldname = "C:\test.doc"
newname = "\\....\test.doc"
FileCopy oldname, newname
End Sub
test.doc


---
Message posted from
http://www.ExcelForum.com/




Tushar Mehta

copy files from one dir to another
 
Suppose the cell is C1. Then use

oldname = "C:\" & range("C1").value
newname = "\\....\" & range("C1").value

To be more specific about which workbook and which worksheet, use
workbooks("wbk name here").Worksheets("wks name here").range
("C1").value
--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , rvik
says...
hai

a cell address contains a file name. i want the file name in the cell
address to be the input for the code below, so that the file is copied
to a new location....i.e. instead of the "test.doc", i should have the
file name mentioned in the cell address


Sub file_trf_copy()
oldname = "C:\test.doc"
newname = "\\....\test.doc"
FileCopy oldname, newname
End Sub
test.doc


---
Message posted from http://www.ExcelForum.com/



rvik[_15_]

copy files from one dir to another
 
Mehta,

no, it didnt work

I get the error file not found, thought the file test.doc is availabl
in c:\

the code is:

Sub file_trf_copy()
oldname = "c:\" & Range("b4").Value
newname = "\\...\..\test.doc"
FileCopy oldname, newname
End Sub


where b4 contains the value "test"..

what am i doing wrong

--
Message posted from http://www.ExcelForum.com


rvik[_16_]

copy files from one dir to another
 
mehta,

yeah.. i got it right. I left out the extension .doc in the cel
address. Once i gave the extension, code worked..

Now a rejoinder to the query, if you all don't mind...

Supposing the file already exits in the destination, then i would lik
to have a pop displaying something like " file already exists, Do yo
want to overwrite? YES / NO"


Thank

--
Message posted from http://www.ExcelForum.com


Tushar Mehta

copy files from one dir to another
 
Use something like:

Option Explicit

Sub testIt()
Dim SrcFilename As String, DestFilename As String
SrcFilename = "C:\" & Range("C1").Value
DestFilename = "\\....\" & Range("C1").Value
If Dir(DestFilename) < "" Then
If MsgBox("File " & DestFilename & _
" exists; OK to overwrite", _
vbOKCancel) = vbCancel Then
Exit Sub '<<<<<
End If
End If
FileCopy SrcFilename, DestFilename
End Sub

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , rvik
says...
mehta,

yeah.. i got it right. I left out the extension .doc in the cell
address. Once i gave the extension, code worked..

Now a rejoinder to the query, if you all don't mind...

Supposing the file already exits in the destination, then i would like
to have a pop displaying something like " file already exists, Do you
want to overwrite? YES / NO"


Thanks


---
Message posted from http://www.ExcelForum.com/




All times are GMT +1. The time now is 06:00 AM.

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