Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Open file - How to test the path ?

Hello,
I have a macro which open a dbf file and copy the information inside excel.

The path and the file name are variable. I need to test the path and the
file to see if it is valid before trying to open it.

example:
if ( c:\temp\ doesn't not exist) then
error message 1
elseif (c:\temp\file.dbf doesn't exist) then
error message 2
else
macro execution
endif

To open the document, I'm using: workbooks.Open "c:\temp\file.dbf"

Thank you !
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Open file - How to test the path ?

if dir("c:\temp\file.dbf") = "" then
msgbox "Doesn't exist"
else
' whatever
End if

no reason to test the items separately - if it doesn't exist, it doesn't
exist.

--
Regards,
Tom Ogilvy

"Alex St-Pierre" wrote in message
...
Hello,
I have a macro which open a dbf file and copy the information inside

excel.

The path and the file name are variable. I need to test the path and the
file to see if it is valid before trying to open it.

example:
if ( c:\temp\ doesn't not exist) then
error message 1
elseif (c:\temp\file.dbf doesn't exist) then
error message 2
else
macro execution
endif

To open the document, I'm using: workbooks.Open "c:\temp\file.dbf"

Thank you !
--
Alex St-Pierre



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Open file - How to test the path ?


"Alex St-Pierre" wrote in message
...
: Hello,
: I have a macro which open a dbf file and copy the information inside
excel.
:
: The path and the file name are variable. I need to test the path and the
: file to see if it is valid before trying to open it.
:
: example:
: if ( c:\temp\ doesn't not exist) then
: error message 1
: elseif (c:\temp\file.dbf doesn't exist) then
: error message 2
: else
: macro execution
: endif
<snip

Use Dir as a check

if Dir(c:\temp) = "" then
error message 1
elseif Dir(c:\temp\file.dbf ) = "" then
error message 2
else
macro execution
endif

Although I'm not sure why you need to check both, if the file does not exist
why does it matter if the directory exists?

Paul D

Paul D


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Open file - How to test the path ?


"PaulD" <nospam wrote in message
...
:
:
: if Dir(c:\temp) = "" then
: error message 1
: elseif Dir(c:\temp\file.dbf ) = "" then
: error message 2
: else
: macro execution
: endif
:
oops, forgot the quotes around the file name / directory


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
Open Dialog Box to return Selected File Path and Not Open it. DMS Excel Programming 4 January 26th 10 12:46 PM
my vlookup path changes when I open the file AliGoLightly Excel Worksheet Functions 1 February 23rd 09 09:52 PM
Open File with Spaces in Path J Excel Programming 5 November 2nd 04 02:52 PM
File open with Path Name rickey24[_8_] Excel Programming 4 July 8th 04 01:04 AM
How set file open path to filepath of file opened with Explorer ? RandyDtg1 Excel Programming 0 May 14th 04 02:05 AM


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