Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Check if file exists...

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"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Check if file exists...

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"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Check if file exists...

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"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Check if file exists...

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" wrote in message
...
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
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
Check if a File Exists Ray Clark[_2_] Excel Programming 4 June 11th 08 05:13 PM
Check if file exists Jon Excel Discussion (Misc queries) 14 October 4th 07 04:57 PM
Loadpicture - check if file exists t0ny Excel Programming 3 December 27th 06 04:01 PM
How do I check if a sheetname exists in a file? NezRhodes Excel Programming 2 August 22nd 06 09:44 AM
check if file exists Curt Excel Programming 0 December 7th 05 05:02 PM


All times are GMT +1. The time now is 12: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"