Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old September 15th 03, 10:29 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Sep 2003
Posts: 2
Default Copying a file with VBA (or with a SHELL command)

Hi,

I'm looking for a solution to make a copy of a file already open.
Function FILECOPY doesn't work because this file is already open...
The file I want to copy is a SYS file so it's impossible to open it in Excel
and save it as...

Would anyone have an idea about it ? If yes, could you please write me a
line of code as example.

Thanks,

Franck V.




  #2   Report Post  
Old September 15th 03, 07:46 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Jul 2006
Posts: 27,285
Default Copying a file with VBA (or with a SHELL command)

You would need to create a reference to the Microsoft Scripting Runtime in
the VBE under tools references. If you don't want to do that, you can use
late binding

Sub TestCopy()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "C:\test.sys", "D:\My Folder\"

End Sub

Make sure you include the last "\" in the destination.

this assume you have the scripting runtime installed - which is highly
probable.

so the original should have been

Dim FSO as FileSystemObject
set FSO = new FileSystemObject
FSO.CopyFile "C:\test.sys", "D:\My Folder\"

--
Regards,
Tom Ogilvy
"Tom Ogilvy" wrote in message
...
Here is the answer I provided to your posting of this question on 12 Sep:

Dim FSO as FileSystemObject
set FSO = new FileSystemObject

FSO.CopyFile "C:\test.sys", "D:\My Folder"

--
Regards,
Tom Ogilvy

------------------------
Here is an answer from Kent Fickle:

Would something like this do it?

Private Declare Function CopyFile _
Lib "kernel32" _
Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Sub test()
CopyFile "C:\Temp\test.txt", "C:\Temp\test2.txt", 0&
End Sub

--------------

--
Regards,
Tom Ogilvy

"Franck V." wrote in message
...
Hi,

I'm looking for a solution to make a copy of a file already open.
Function FILECOPY doesn't work because this file is already open...
The file I want to copy is a SYS file so it's impossible to open it in

Excel
and save it as...

Would anyone have an idea about it ? If yes, could you please write me a
line of code as example.

Thanks,

Franck V.









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
How to use the "shell" command? Tom Excel Discussion (Misc queries) 11 April 27th 10 12:52 AM
Running Shell Jeff Excel Discussion (Misc queries) 0 January 28th 08 04:50 PM
IF command and copying and pasting whole rows Schwimms Excel Discussion (Misc queries) 0 May 25th 07 08:00 PM
Shell Statement [email protected] Excel Programming 1 August 13th 03 08:19 PM
use shell function in vbscript Sofia Excel Programming 0 July 21st 03 06:29 PM


All times are GMT +1. The time now is 08:12 PM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017