Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default 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/




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default 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/


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy files to clipboard wyn Excel Discussion (Misc queries) 0 July 30th 08 12:15 PM
Copy Files with Links John Lam Excel Discussion (Misc queries) 0 March 9th 07 04:01 AM
Copy and Paste Between Files Dragon Excel Discussion (Misc queries) 1 February 5th 07 04:26 AM
Compare name and copy from closed .csv files Mikke Excel Worksheet Functions 0 May 12th 06 11:49 PM
Copy range of many files in directory. CLUPE Excel Programming 1 July 15th 03 04:37 PM


All times are GMT +1. The time now is 07:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"