Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Moving Files and creating copies

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Moving Files and creating copies

I would think that using SaveAs with the full path would allow you to move
and rename the files in one fell swoop.

"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Moving Files and creating copies

I would recommend using some addition to the filename. I typically use
something extra like date and time information added to the original
filename to avoid overwriting previous versions of the same file.

If you need some examples, let me know.

Mark

"Nils Titley" wrote in message
...
FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them
with
a new name. If not how can I do that?

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Moving Files and creating copies

Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Moving Files and creating copies

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Moving Files and creating copies

Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.



"Ron de Bruin" wrote:

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Moving Files and creating copies

You could try copying files individually using FSO File.Move, and if it
returns 'file exists' error (58), use a different name. Something like this
(please be careful, this is not tested):

strSourceFolder = "c:\source\"
strDestFolder = "d:\destination\"

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objSourceFolder = objFso.GetFolder(strSourceFolder)

For Each objFile In objSourceFolder.Files

On Error Resume Next

objFile.Move strDestFolder

If Err.Number = 58 Then
i = 1
Do While Err.Number < 0

Err.Clear

objFile.Move strDestFolder & "Copy Of " & _
objFso.GetBaseName(objFile) & _
" (" & i & ")" & "." & _
objFso.GetExtensionName(objFile.Path)

i = i + 1

Loop
Else
Debug.Print Err.Number, Err.Description
End If

On Error GoTo 0

Next


--
urkec


"Nils Titley" wrote:

Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.



"Ron de Bruin" wrote:

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Moving Files and creating copies

Hi Nils

Checking if each file exist in a loop is the only way.


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.



"Ron de Bruin" wrote:

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Moving Files and creating copies

Thanks for the help. I will give it a try. I dont' think it is necessary to
check if they exist but better to check than to get an error and have the
move fail. I don't think it is necessary to check because I don't think
there will be duplicate files.



"Nils Titley" wrote:

Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.



"Ron de Bruin" wrote:

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Moving Files and creating copies

Urkec,

Your code worked perfectly. Thanks for helping me.



"urkec" wrote:

You could try copying files individually using FSO File.Move, and if it
returns 'file exists' error (58), use a different name. Something like this
(please be careful, this is not tested):

strSourceFolder = "c:\source\"
strDestFolder = "d:\destination\"

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objSourceFolder = objFso.GetFolder(strSourceFolder)

For Each objFile In objSourceFolder.Files

On Error Resume Next

objFile.Move strDestFolder

If Err.Number = 58 Then
i = 1
Do While Err.Number < 0

Err.Clear

objFile.Move strDestFolder & "Copy Of " & _
objFso.GetBaseName(objFile) & _
" (" & i & ")" & "." & _
objFso.GetExtensionName(objFile.Path)

i = i + 1

Loop
Else
Debug.Print Err.Number, Err.Description
End If

On Error GoTo 0

Next


--
urkec


"Nils Titley" wrote:

Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.



"Ron de Bruin" wrote:

See also
http://www.rondebruin.nl/folder.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Nils Titley" wrote in message ...
Let me provide additional information.

The macro will be used by all sorts of people. I want to make it easy for
them. There is a data folder and an archive folder. The macro process any
file that sits in the data folder. After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.

I want to move all of the data files to the archive folder. I can do that
now. But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder. I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks


"Nils Titley" wrote:

FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name. If not how can I do that?

Thanks

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 do I stop Excel 2007 from creating backup copies? KLB[_2_] Excel Discussion (Misc queries) 3 April 4th 23 10:26 AM
Moving between cells copies the screen! RuiP Excel Discussion (Misc queries) 1 October 14th 05 02:07 PM
how can i stop excel from automatically creating copies of workbo. Automac Parking Excel Worksheet Functions 0 October 12th 05 06:59 PM
How do I stop Excel from making copies of files? wlewismba Excel Discussion (Misc queries) 1 April 30th 05 04:28 PM
Creating two linked copies of one workbook Jim Excel Discussion (Misc queries) 3 March 23rd 05 08:20 AM


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

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"