PC Review


Reply
Thread Tools Rate Thread

Check if file exists...

 
 
=?Utf-8?B?YWJkcnVtcw==?=
Guest
Posts: n/a
 
      12th Jul 2007
I use the following to save a file to folder. How can I have it check
to see if the filepath exists and it exits then msgbox indicated that file
is there and exit sub routine, and if not exists, go ahead and create the
path?

ActiveWorkbook.SaveAs Filename:="\\my path directory\" & NewFileName & ".xls"

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cDQ1Y2Fs?=
Guest
Posts: n/a
 
      12th Jul 2007
see
http://j-walk.com/ss/excel/tips/tip54.htm
--
p45cal


"abdrums" wrote:

> I use the following to save a file to folder. How can I have it check
> to see if the filepath exists and it exits then msgbox indicated that file
> is there and exit sub routine, and if not exists, go ahead and create the
> path?
>
> ActiveWorkbook.SaveAs Filename:="\\my path directory\" & NewFileName & ".xls"
>

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      12th Jul 2007
try something like this:

If Dir("\\my path directory\" & NewFileName & ".xls") = "" Then
ActiveWorkbook.SaveAs Filename:="\\my path directory\" & NewFileName &
".xls"
Else
MsgBox "File already exists!"
Exit Sub
End If



--
Hope that helps.

Vergel Adriano


"abdrums" wrote:

> I use the following to save a file to folder. How can I have it check
> to see if the filepath exists and it exits then msgbox indicated that file
> is there and exit sub routine, and if not exists, go ahead and create the
> path?
>
> ActiveWorkbook.SaveAs Filename:="\\my path directory\" & NewFileName & ".xls"
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      13th Jul 2007
Not sure if you are talking about file or path to exist. You have some
suggestions already, but here's another.
You can use the Windows API to check/create a path:

<API-Guide>
Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal
lpPath As String) As Long

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
</API-Guide>

NickHK

"abdrums" <(E-Mail Removed)> wrote in message
news:AD02684E-12EE-42A7-BE51-(E-Mail Removed)...
> I use the following to save a file to folder. How can I have it check
> to see if the filepath exists and it exits then msgbox indicated that file
> is there and exit sub routine, and if not exists, go ahead and create the
> path?
>
> ActiveWorkbook.SaveAs Filename:="\\my path directory\" & NewFileName &

".xls"
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
check file exists iccsi Microsoft Access Form Coding 3 6th Feb 2009 05:02 PM
Check if file exists WembleyBear Microsoft Excel Programming 3 19th May 2008 04:39 PM
Check if File exists Ricardo Luceac Microsoft C# .NET 10 23rd Jan 2006 02:41 PM
how to check if the file exists or not Mili Microsoft Excel Discussion 1 6th Nov 2003 11:45 AM
Check if file exists Newbie Microsoft Access Form Coding 3 4th Nov 2003 05:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 AM.