OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Thread Tools Search this Thread Display Modes
Old 01-03-2004, 10:02
Rick Randall
Posts: n/a
Default Checking if a file exists before importing

I need to check if a file exist before I try and import it. Here’s what I’ve got:
Dim fso As New FileSystemObject


If fso.FileExists(“C:\test.gif") = True Then

What am I doing wrong?
Reply With Quote
Old 01-03-2004, 11:33
Alex's Avatar
Alex Alex is offline
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default Re: Checking if a file exists before importing

What result do you get? Run-time error? Wrong result of check for file existance? Something else?

Have you referenced the file system object library (Microsoft Scripting Runtime) in your VBA project (Toos>References dialog)?

I just did a very quick test and it seemed to work OK:

Sub Test()
    Dim fso As New FileSystemObject
    If fso.FileExists("C:\Temp.gif") Then
        MsgBox "Exists"
        MsgBox "Does not exist"
    End If
End Sub
Another thing is why do you use FileSystemObject if you can use VBA's native functions such as GetAttr or even Dir:

Sub Test2()
    If Dir("C:\Temp.gif") <> "" Then
        MsgBox "Exists"
        MsgBox "Does not exist"
    End If
End Sub

Sub Test3()
    Dim attr As VbFileAttribute
    On Error Resume Next
    attr = GetAttr("C:\Temp.gif")
    If Err.Number = 0 And (attr And (vbArchive + vbHidden + vbNormal + vbReadOnly)) <> 0 Then
        MsgBox "Exists"
        MsgBox "Does not exist"
    End If
End Sub
I hope this helps.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
delete vba project from cdr file hotairballoon CorelDRAW/Corel DESIGNER VBA 1 18-05-2005 10:08
Importing from dialog... ddonnahoe CorelDRAW/Corel DESIGNER VBA 0 25-01-2005 09:26
File Convertor to do transpararent TIFFs dan CorelDRAW/Corel DESIGNER VBA 8 22-12-2004 14:23
Finding a File in Sub Folders shelbym CorelDRAW/Corel DESIGNER VBA 10 10-05-2004 09:02
Open - Resize - Savefile in Photo Paint greenee Corel Photo-Paint VBA 2 28-06-2003 04:54

All times are GMT -5. The time now is 18:06.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com