ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open file - How to test the path ? (https://www.excelbanter.com/excel-programming/322581-open-file-how-test-path.html)

Alex St-Pierre

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

Tom Ogilvy

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




PaulD

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



PaulD

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




All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com