COPY A FILE OUTSIDE OF EXCEL!

  • Thread starter Thread starter 2007-User
  • Start date Start date
2

2007-User

Hi,

I have a file called "E:\ENGINEERING FOLDER\001-Ready\Template.ecw" I would
like to copy this file to the same directory that my current excel file is
stored and running, after that I would like to rename this new file to "
current excel file name.ecw " , is this possible?
can anyone please help me to create this VBA?

Thanks in advance.
 
With ThisWorkbook
Name "E:\ENGINEERING FOLDER\001-Ready\Template.ecw" As .Path & "\" &
Left(.Name, Len(.Name) - 4) & ".ecw"
End With

NickHK
 
Try the code below:

Option Explicit

Private Sub CopyFile()
Dim strSourcePath As String
Dim strSourceFile As String
Dim strTargetPath As String
Dim strTargetFile As String
Dim oFS As Object
Dim oFile As Object

strSourcePath = "C:\temp\"
strSourceFile = "myfile.ecw"
strTargetPath = ActiveWorkbook.Path & "\"
strTargetFile = Left(ActiveWorkbook.Name,
InStr(ActiveWorkbook.Name, ".") - 1) & ".ecw"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.Copy(strTargetPath & strTargetFile)
Set oFile = Nothing
Set oFS = Nothing
End Sub
 
Nick

I didn't know about the "Name" command in VBA.

Neat solution.
 
Hi 2007-user,
try this one, maybe solve ur problem:

Sub CopyFile()
Dim currentfilename

currentfilename = mid(ActiveWorkbook.Name,1,len(ActiveWorkbook)-4)
' _
'if your ActiveWorkbook is has path, to prevent doubled file extention.
'currentfilename =ActiveWorkbook 'if ur ActiveWorkbook not saved

FileCopy "E:\ENGINEERING FOLDER\001-Ready\Template.ecw", _
"E:\ENGINEERING FOLDER\001-Ready\" & currentfilename & ".ecw"

End Sub

Regards,

Halim



2007-User menuliskan:
 
Thanks a lot for all of your responses, I'll try those solutions and let you
know bout the results...
 

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

Back
Top