LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default File Management using VBA

I've never come across help sources/tutorials on file management, but I've
never looked very hard either.

To test to see if a file name already exists, you could use the Dir function

If Dir("C:\myfile.xls") = "" Then
'File does not exist
Else
'File already exists
End If

but you have to decide what to do if the file already exists (overwrite,
cancel, try to programmatically develop another file name, use an inputbox to
get a file name from the user, etc).


"C Brandt" wrote:

JMB:

Thanks for your response. It was right on target.

It is amazing at how simple the solution is once you know how. Knowing the
answer, I went to do more research on "NAME" and it was no help. I never
would have figured it out without your help.

Do you know of any online help source that takes about how to handle file
management, like what to do when you have file name conflicts, etc? (Clear
examples always help.)

Thanks again,

Craig

"JMB" wrote in message
...
I believe you could also use the Name statement

Dim OldName As String, NewName As String
OldName = "c:\account.txt"
NewName = "c:\acct" & Format(Now(), "mmddyy") & ".txt"
Name OldName As NewName ' Rename file.

or

OldName = "c:\account.txt"
NewName = "C:\YOURDIR\"acct" & Format(Now(), "mmddyy") & ".txt"
Name OldName As NewName ' Move and rename file.

although if you want to use yesterday's date in the filename, you may want
to use Now()-1. or if you want to use the previous workday (see XL help

for
workday function), perhaps use
"acct" & Format(evaluate("workday(now(),-1)"), "mmddyy") & ".txt"
but holidays could potentially cause problems.


"C Brandt" wrote:

Hi Guys:

I need to change the name of a downloaded file
Example: An outside system creates a file "account.txt", on my system,

every
morning and cannot tolerate having an existing file with that name. I

would
like to change the name to "acct062507.txt" for the data gathered on the
25th of June.
This probably needs to be a standalone task, scheduled to run every

morning
prior to the download (move yesterdays file to make room for the new
download).
Can someone point me to online help that gives examples of this type of
work?

Very much appreciated,
Craig








 
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
Leave Management jai Excel Discussion (Misc queries) 2 June 11th 07 12:59 PM
Project Management Radiate Excel Discussion (Misc queries) 1 October 9th 06 02:53 PM
Memory and File Size Management MMcCullough Excel Discussion (Misc queries) 12 August 12th 06 01:48 AM
Text Management Sprite8 Excel Discussion (Misc queries) 2 January 3rd 06 06:36 PM
Risk management Ole w Excel Discussion (Misc queries) 0 July 28th 05 01:35 PM


All times are GMT +1. The time now is 05:31 AM.

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

About Us

"It's about Microsoft Excel"