OberonPlace.com Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-03-2004, 09:02
Rick Randall
Guest
 
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:
Code:
Dim fso As New FileSystemObject

 

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

….
What am I doing wrong?
Reply With Quote
  #2  
Old 01-03-2004, 10:33
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
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:

Code:
Sub Test()
    Dim fso As New FileSystemObject
    If fso.FileExists("C:\Temp.gif") Then
        MsgBox "Exists"
    Else
        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:

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

Code:
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"
    Else
        MsgBox "Does not exist"
    End If
End Sub
I hope this helps.
Reply With Quote
Reply


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 09:08
Importing from dialog... ddonnahoe CorelDRAW/Corel DESIGNER VBA 0 25-01-2005 08:26
File Convertor to do transpararent TIFFs dan CorelDRAW/Corel DESIGNER VBA 8 22-12-2004 13:23
Finding a File in Sub Folders shelbym CorelDRAW/Corel DESIGNER VBA 10 10-05-2004 08:02
Open - Resize - Savefile in Photo Paint greenee Corel Photo-Paint VBA 2 28-06-2003 03:54


All times are GMT -5. The time now is 02:07.


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